How does it work ?

This API will help you store and retrieve information about restaurants.
Four HTTP endpoints are here for you to use:

GET Get all restaurants #

This API endpoint is public and exposes a list of all the restaurants in The Fork:

GET https://the-fork-api.students.lewagon.engineering/api/v1/restaurants

It does not require a Bearer token.

Try it in your terminal by running:
curl --request GET https://the-fork-api.students.lewagon.engineering/api/v1/restaurants | jq
NB: jq is a binary that highlights the response in the terminal.
{
  "data": [
    {
    "id": 1,
    "name": "Red Pizza",
    "address": "Apt. 120 8318 Ledner Pines, New Brockfurt, ND 37989-9210",
    "category": "italian",
    "user_id": 1,
    "created_at": "2023-01-12T14:50:43.902Z",
    "updated_at": "2023-01-12T14:50:43.902Z"
    },
    {
    "id": 2,
    "name": "Fast Sushi",
    "address": "5682 O'Keefe Crossroad, Kochfurt, RI 87403-4649",
    "category": "japanese",
    "user_id": 2,
    "created_at": "2023-01-12T14:50:43.912Z",
    "updated_at": "2023-01-12T14:50:43.912Z"
    },
    // [...] and more items
  ]
}
      

The public endpoint that exposes the list of all restaurants can also be used to search restaurants, simply by adding a query string with the location or category. It does not require a Bearer token.

GET https://the-fork-api.students.lewagon.engineering/api/v1/restaurants?category=italian&location=kochfurt
Try it in your terminal by running:
curl --request GET https://the-fork-api.students.lewagon.engineering/api/v1/restaurants?category=italian&location=kochfurt | jq

If there's restaurants with the category "italian" and location "kochfurt"

{
  "data": [
    {
    "id": 2,
    "name": "Pasta e Basta",
    "address": "5682 O'Keefe Crossroad, Kochfurt, RI 87403-4649",
    "category": "italian",
    "user_id": 2,
    "created_at": "2023-01-12T14:50:43.912Z",
    "updated_at": "2023-01-12T14:50:43.912Z"
    }
  ]
}
      

If there's no results

{
  "data": [ ]
}
      

GET Get infos for a restaurant #

This API endpoint exposes the information for a specific restaurant in The Fork:

GET https://the-fork-api.students.lewagon.engineering/api/v1/restaurants/:id

This endpoint is private and requires a bearer token, which you will find on your profile page once you are signed in.

Try it in your terminal by running:
curl --request GET \ -H 'X-User-Email: your-email' \ -H 'X-User-Token: your-token' \ https://the-fork-api.students.lewagon.engineering/api/v1/restaurants/10 | jq
{
  "data": [
    {
      "id": 10,
      "name": "Golden Cafe",
      "address": "Suite 550 4701 Balistreri Roads, South Charoletteberg, MN 81307",
      "category": "indian",
      "user_id": 3,
      "created_at": "2023-01-12T14:50:43.954Z",
      "updated_at": "2023-01-12T14:50:43.954Z"
    }
  ]
}
      

If your request is not authenticated:

{
  "error": "You need to sign in or sign up before continuing."
}
      

POST Add a restaurant #

This API endpoint enables you to add a restaurant to The Fork:

POST https://the-fork-api.students.lewagon.engineering/api/v1/restaurants

This endpoint is private and requires a bearer token, which you will find on your profile page once you are signed in.

Please note that some conditions need to be met in order to create a new restaurant. In particular, category must be included in this list:

italian chinese vietnamese japanese korean spanish french mexican indian
Try it in your terminal by running:
curl --request POST \ -H 'Content-Type: application/json' \ -H 'X-User-Email: your-email' \ -H 'X-User-Token: your-token' \ -d '{ "restaurant": { "name": "New restaurant", "address": "London", "category": "korean" } }' \ https://the-fork-api.students.lewagon.engineering/api/v1/restaurants | jq
{
  "data": [
    {
      "id":5,
      "name":"New restaurant",
      "address":"London",
      "category":"korean",
      "user_id":4,
      "created_at":"2023-01-12T18:29:39.201Z",
      "updated_at":"2023-01-12T18:29:39.201Z"
    }
  ]
}
      

If a field is missing:

{
  "errors": ["Address can't be blank"]
}
      

If your request is not authenticated:

{
  "error": "You need to sign in or sign up before continuing."
}
      

DELETE Delete a restaurant #

This API endpoint enables you to destroy a restaurant from The Fork:

DELETE https://the-fork-api.students.lewagon.engineering/api/v1/restaurants/:id

This endpoint is private and requires a bearer token, which you will find on your profile page once you are signed in.

Try it in your terminal by running:
curl --request DELETE \ -H 'X-User-Email: your-email' \ -H 'X-User-Token: your-token' \ https://the-fork-api.students.lewagon.engineering/api/v1/restaurants/12 | jq
{
  "message": "Restaurant deleted"
}
      

If your request is not authenticated:

{
  "error": "You need to sign in or sign up before continuing."
}
      

GET Get the chef for one restaurant #

This API endpoint exposes the chef for a specific restaurant in The Fork:

GET https://the-fork-api.students.lewagon.engineering/api/v1/restaurants/:id/chef

This endpoint is private and requires a bearer token, which you will find on your profile page once you are signed in.

For this endpoint you can choose what type of request you want back.

Simply by appending the url with .xml it will return a XML response. Appending the url with .json will return a JSON.

Back in the day XML was widely used as the main type of response for API's, until JSON took over.


Try it in your terminal by running:
curl --request GET \ -H 'X-User-Email: your-email' \ -H 'X-User-Token: your-token' \ https://the-fork-api.students.lewagon.engineering/api/v1/restaurants/10/chef.xml

  <?xml version="1.0" encoding="UTF-8"?>
  <hash>
    <id type="integer">12</id>
    <name>Douglas</name>
    <years-of-experience type="integer">18</years-of-experience>
    <avatar-url>https://unsplash.com/photos/KTrov7eujms</avatar-url>
    <restaurant-id type="integer">14</restaurant-id>
    <created-at type="dateTime">2023-01-26T14:38:58Z</created-at>
    <updated-at type="dateTime">2023-01-26T14:38:58Z</updated-at>
  </hash>

      

If your request is not authenticated:


  <?xml version="1.0" encoding="UTF-8"?>
  <errors>
    <error>You need to sign in or sign up before continuing.</error>
  </errors>

      
Try it in your terminal by running:
curl --request GET \ -H 'X-User-Email: your-email' \ -H 'X-User-Token: your-token' \ https://the-fork-api.students.lewagon.engineering/api/v1/restaurants/10/chef.json
{
  "id": 28,
  "name": "Chef Romaguera",
  "years_of_experience": 14,
  "avatar_url": "https://unsplash.com/photos/kImU-9S9uh8",
  "restaurant_id": 30,
  "created_at": "2023-01-31T09:53:54.423Z",
  "updated_at": "2023-01-31T09:53:54.423Z"
}
      

If the restaurant does not exist:

{
  "error": "Couldn't find Restaurant with 'id'=10"
}
      

If your request is not authenticated:

{
  "error": "You need to sign in or sign up before continuing."
}