Our video store API should be able to work with two entities, Customer
and Video
.
Customers are entities that describe a customer at the video store. They contain:
- name of the customer
- postal code of the customer
- phone number of the customer
- register_at datetime of when the customer was added to the system
- videos_checked_out_count of how many videos the customer currently has checked out
Videos are entities that describe a video at the video store. They contain:
- title of the video
- release date datetime of when the video was release_date
- total inventory of how many copies are owned by the video store
Our goal for this wave is to be able to do all CRUD actions for these two entities. We will create RESTful routes for this different operations.
It's crucial for all APIs to be able to handle errors. For every required endpoint described in this project, handle errors in this pattern.
If something goes wrong...
- Your API should return an appropriate HTTP status code.
- For POST and PUT requests, responses with 4XX response codes should also return a response body with some indication of what went wrong.
If something goes wrong...
- Your API should return an appropriate HTTP status code.
- For POST and PUT requests, responses with 4XX response codes should also return a response body with some indication of what went wrong.
This could be something as simple as:
{
"details": "Invalid data"
}
...or something slightly more complex like:
[
"title must be provided and it must be a string",
"total_inventory must be provided and it must be a number"
]
Some of the tests require a particular response body for 400 levels responses. In other cases, you are free to choose.
Here we will list every endpoint for these entities.
Every endpoint must serve JSON data, and must use HTTP response codes to indicate the status of the request.
Required RESTful endpoints:
- GET
/customers
- GET
/customers/<id>
- POST
/customers
- PUT
/customers/<id>
- DELETE
/customers/<id>
Lists all existing customers and details about each customer.
No arguments to this request
Typical success response:
Status: 200
[
{
"id": 1,
"name": "Shelley Rocha",
"registered_at": "Wed, 29 Apr 2015 07:54:14 -0700",
"postal_code": "24309",
"phone": "(322) 510-8695"
},
{
"id": 2,
"name": "Curran Stout",
"registered_at": "Wed, 16 Apr 2014 21:40:20 -0700",
"postal_code": "94267",
"phone": "(908) 949-6758"
}
]
- The API should return an empty array and a status
200
if there are no customers.
Gives back details about specific customer.
Arg | Type | Details |
---|---|---|
id |
integer | The id of the customer |
Typical success response (these are the minimum required fields that the Postman tests will be looking for):
Status: 200
{
"id": 2,
"name": "Curran Stout",
"registered_at": "Wed, 16 Apr 2014 21:40:20 -0700",
"postal_code": "94267",
"phone": "(908) 949-6758"
}
- The API should return back detailed errors and a status
404: Not Found
if this customer does not exist.
Creates a new video with the given params.
Request Body Param | Type | Details |
---|---|---|
name |
string | The name of the customer |
postal_code |
string | The postal code of the customer |
phone |
string | The phone of the customer |
Typical success response, where id
is the id of the new customer (this is the minimum required field that the Postman tests will be looking for):
Status: 201: Created
{
"id": 10034
}
- The API should return back detailed errors and a status
400: Bad Request
if the customer does not have any of the required fields to be valid.
Updates and returns details about specific customer.
Arg | Type | Details |
---|---|---|
id |
integer | The id of the customer |
Request Body Param | Type | Details |
---|---|---|
name |
string | The name of the customer |
postal_code |
string | The postal code of the customer |
phone |
string | The phone of the customer |
Typical success response (these are the minimum required fields that the Postman tests will be looking for):
Status: 200
{
"id": 2,
"name": "Curran Stout",
"registered_at": "Wed, 16 Apr 2014 21:40:20 -0700",
"postal_code": "94267",
"phone": "(908) 949-6758"
}
- The API should return back detailed errors and a status
404: Not Found
if this customer does not exist. - The API should return a
400: Bad Request
, if any of the request body fields are missing or invalid.- For example if the
name
is an empty string or is not a string.
- For example if the
Deletes a specific customer.
Arg | Type | Details |
---|---|---|
id |
integer | The id of the customer |
Typical success response (these are the minimum required fields that the Postman tests will be looking for):
Status: 200
{
"id": 2
}
- The API should return back detailed errors and a status
404: Not Found
if this customer does not exist.
Required RESTful endpoints:
- GET
/videos
- GET
/vidoes/<id>
- POST
/videos
- PUT
/videos/<id>
- DELETE
/videos/<id>
Lists all existing videos and details about each video.
No arguments to this request
Typical success response (this are the minimum required fields that the Postman tests will be looking for):
Status: 200
[
{
"id": 1,
"title": "Blacksmith Of The Banished",
"release_date": "1979-01-18",
"total_inventory": 10
},
{
"id": 2,
"title": "Savior Of The Curse",
"release_date": "2010-11-05",
"total_inventory": 11
}
]
- The API should return an empty array and a status
200
if there are no videos.
Gives back details about specific video in the store's inventory.
Arg | Type | Details |
---|---|---|
id |
integer | The id of the video |
Typical success response (this are the minimum required fields that the Postman tests will be looking for):
Status: 200
{
"id": 1,
"title": "Blacksmith Of The Banished",
"release_date": "1979-01-18",
"total_inventory": 10
}
- The API should return back detailed errors and a status
404: Not Found
if this video does not exist.
Creates a new video with the given params.
Request Body Param | Type | Details |
---|---|---|
title |
string | The title of the video |
release_date |
datetime | Represents the date of the video's release |
total_inventory |
integer | The total quantity of this video in the store |
Typical success response, where id
is the id of the new video (this is the minimum required field that the Postman tests will be looking for):
Status: 201: Created
{
"id": 277419104
}
- The API should return back detailed errors and a status
400: Bad Request
if the video does not have any of the required fields to be valid.
Gives back details about specific video in the store's inventory.
Arg | Type | Details |
---|---|---|
id |
integer | The id of the video |
Request Body Param | Type | Details |
---|---|---|
title |
string | The title of the video |
release_date |
datetime | Represents the date of the video's release |
total_inventory |
integer | The total quantity of this video in the store |
Typical success response (this are the minimum required fields that the Postman tests will be looking for):
Status: 200
{
"id": 1,
"title": "Blacksmith Of The Banished",
"release_date": "1979-01-18",
"total_inventory": 10
}
- The API should return back detailed errors and a status
404: Not Found
if this video does not exist. - The API should return back a
400 Bad Request
response for missing or invalid fields in the request body.- For example, if
total_inventory
is missing or is not a number
- For example, if
Deletes a specific video.
Arg | Type | Details |
---|---|---|
id |
integer | The id of the video |
Typical success response (these are the minimum required fields that the Postman tests will be looking for):
Status: 200
{
"id": 12
}
- The API should return back detailed errors and a status
404: Not Found
if this video does not exist.