-
Notifications
You must be signed in to change notification settings - Fork 0
API Restaurant Endpoints
Endpoints and HTTP verbs used for Espresso restaurants that have been implemented.
N.B. All input string fields are silently truncated to 255 characters without reporting an error or raising an exception if a field exceeds that number of characters
List all restaurants, returning all fields for each.
No input arguments.
In all cases the returned object contains a success
boolean property at the top-level.
Examples of returned json are below. The id
property is a non-negative integer. The name
property is not blank or null. All other properties are free-form strings that may be empty or null.
(1) The happy path returning two restaurants, status code 200
{
"api_version": "2.0",
"message": null,
"restaurants": [
{
"city": "San Francisco",
"creator": "[email protected]",
"date_established": "August 2020",
"email": null,
"id": 7,
"name": "Herbal",
"phone_num": "(415) 896-4839",
"state": "CA",
"street": "448 Larkin St",
"suite": null,
"website": "https://www.herbalrestaurant.com/",
"zip_code": "94102"
},
{
"city": "San Francisco",
"creator": "[email protected]",
"date_established": "Pre 2004",
"email": null,
"id": 8,
"name": "Chutney",
"phone_num": "(415) 931-5541",
"state": "CA",
"street": "511 Jones St",
"suite": null,
"website": "https://www.chutneysanfrancisco.com/",
"zip_code": "94102"
}
],
"success": true
}
(2) The happy path when there are no restaurants, status code 200
{
"api_version": "2.0",
"message": null,
"restaurants": [],
"success": true
}
(3) The sad path with an internal server error, e.g. database table does not exist, status code 500
{
"api_version": "2.0",
"message": "Server failure: list of restaurants could not be retrieved",
"restaurants": null,
"success": false
}
List a single restaurant. Return all of its fields.
One input argument {:id} consisting of a positive integer that uniquely identifies the restaurant.
Examples of returned json.
(1) The happy path returning an existing restaurant, status code 200
{
"api_version": "2.0",
"id": "2",
"message": null,
"restaurant": {
"city": "San Francisco",
"creator": "[email protected]",
"date_established": "Pre 2004",
"email": null,
"id": 2,
"name": "Chutney",
"phone_num": "(415) 931-5541",
"state": "CA",
"street": "511 Jones St",
"suite": null,
"website": "https://www.chutneysanfrancisco.com/",
"zip_code": "94102"
},
"success": true
}
(2) The sad path for a non-existent restaurant, status code 404
{
"api_version": "2.0",
"id": "6",
"message": "No restaurant with id 6 found",
"restaurant": null,
"success": false
}
(3) The sad path for a non-integer input argument, status code 400
{
"api_version": "2.0",
"id": "xyz",
"message": "Server failure: restaurant with id number xyz could not be retrieved",
"restaurant": null,
"success": false
}
Create a restaurant, returning an object that contains a success
boolean property and a message
.
An example of json for the request is below. The name
property is required and may not be blank or null. All other properties are free-form strings that may be omitted or empty or null.
(1) The happy path with a restaurant created, status code 200
Example of json in the body of the post request:
{
"name": "Kraving Kebab Pizza",
"street": "999 Hackensack St",
"city": "Wood-Ridge",
"state": "NJ",
"phone_num": "201-555-7777",
"website": "www.chinois-nj.com",
"email": "[email protected]"
"creator": "[email protected]",
}
and the resulting json response:
{
"api_version": "2.0",
"id": 6,
"message": "Restaurant created with name: Kraving Kebab Pizza",
"restaurant": {
"city": "Wood-Ridge",
"creator": "[email protected]",
"email": "[email protected]"
"id": 6,
"name": "Kraving Kebab Pizza",
"phone_num": "201-555-7777",
"state": "NJ",
"street": "999 Hackensack St",
"suite": null,
"website": "www.chinois-nj.com",
"zip_code": null
},
"success": true
}
(2) A sad path where the name of the restaurant is missing or blank, status code 400
The json response:
{
"api_version": "2.0",
"id": null,
"message": "Name of restaurant is required",
"restaurant": null,
"success": false
}
Update a restaurant, returning an object that contains a success
boolean property and a message
.
An example of json for the request is below. If the name
property is present, it may not be an empty string or null. All other properties are optional free-form strings that may be empty strings or null.
(1) The happy path with a restaurant updated, status code 200
Example of json in the body of the post request:
{
"website": "www.mexicano-nj.com",
"email": "[email protected]"
}
and the resulting json response:
{
"api_version": "2.0",
"id": 6,
"message": "Restaurant updated: Kraving Kebab Pizza",
"restaurant": {
"city": "San Francisco",
"creator": "[email protected]",
"date_established": "Pre 2004",
"email": "[email protected]",
"id": 2,
"name": "Chutney",
"phone_num": "(415) 931-5541",
"state": "CA",
"street": "511 Jones St",
"suite": null,
"website": "www.mexicano-nj.com",
"zip_code": "94102"
},
"success": true
}
(2) A sad path where the name of the restaurant is an empty string, status code 400
The json response:
{
"api_version": "2.0",
"id": 6,
"message": "Name of restaurant may not be blank",
"restaurant": null,
"success": false
}
One input argument {:id} consisting of a positive integer that uniquely identifies the restaurant.
Delete the restaurant with the given id, returning an object that contains a success
boolean property and a message
.
Examples of returned json.
(1) The happy path with a restaurant deleted, status code 200
{
"api_version": "2.0",
"id": "6",
"message": "Restaurant deleted: Kraving Kebab Pizza",
"restaurant": null,
"success": true
}
(2) A sad path where the id of the restaurant is not found, status code 404
{
"api_version": "2.0",
"id": "6",
"message": "No restaurant with id 6 found",
"restaurant": null,
"success": false
}