Code Monkey home page Code Monkey logo

video-store-api's Introduction

Here we will list every endpoint for this API.

Every endpoint must serve JSON data, and must use HTTP response codes to indicate the status of the request.

Error Handling Requirements for Every Endpoint

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:

For this project, the list of errors should be formatted like this:

{
  "errors": {
    "available_inventory": [
      "can't be blank",
      "is not a number"
    ]
  }
}

// ...or...

{
    "errors": [
        "Not Found"
    ]
}

All errors your API can return should be covered by at least one controller test case.

Wave 1: Customers and Videos

/customers CRUD

Required endpoints:

  1. GET /customers
  2. GET /customers/<id>
  3. POST /customers
  4. PUT /customers/<id>
  5. DELETE /customers/<id>

GET /customers Details

Lists all existing customers and details about each customer.

Required Arguments

No arguments to this request

Response

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",
    "videos_checked_out_count": 0
  },
  {
    "id": 2,
    "name": "Curran Stout",
    "registered_at": "Wed, 16 Apr 2014 21:40:20 -0700",
    "postal_code": "94267",
    "phone": "(908) 949-6758",
    "videos_checked_out_count": 0
  }
]

Errors & Edge Cases to Check

  • The API should return an empty array and a status 200 if there are no customers.

/videos CRUD

Required endpoints:

  1. GET /videos
  2. GET /vidoes/<id>
  3. POST /videos
  4. PUT /videos/<id>
  5. DELETE /videos/<id>

GET /videos Details

Lists all existing videos and details about each video.

Required Arguments

No arguments to this request

Response

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,
    "available_inventory": 9
  },
  {
    "id": 2,
    "title": "Savior Of The Curse",
    "release_date": "2010-11-05",
    "total_inventory": 11,
    "available_inventory": 1
  }
]

Errors & Edge Cases to Check

  • The API should return an empty array and a status 200 if there are no videos.

GET /video/:id Details

Gives back details about specific video in the store's inventory.

Required Arguments

Arg Type Details
id integer The id of the video

Response

Typical success response:

Status: 200

{
  "id": 1,
  "title": "Blacksmith Of The Banished",
  "release_date": "1979-01-18",
  "total_inventory": 10,
  "available_inventory": 9
}

Errors & Edge Cases to Check

  • The API should return back detailed errors and a status 404: Not Found if this video does not exist.

POST /videos

Creates a new video with the given params.

Required Request Body Parameters

Request Body Param Type Details
title string The title of the video
overview string An overview of the video
release_date string Represents the date of the video's release
total_inventory integer The total quantity of this video in the store

Response

Typical success response, where id is the id of the new video:

Status: 201: Created

{
  "id": 277419104
}

Errors & Edge Cases to Check

  • 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.

Hint: Params Not Nested

Are you having trouble creating a new video? Look at the structure of the request body for the request. In Rails, the Rails convention for passing in params often relied on a specific nested structure. For example, when we created a book in Ada Books, our book params data from our new book form came in nested, like {book: {title: 'Alice in Wonderland'}}. How are the API expectations different?

Optional Wave 2: Making Rentals with Checking In and Checking Out

POST /rentals/check-out

Checks out a video to a customer, and updates the data in the database as such.

When successful, this request should:

  • increase the customer's videos_checked_out_count by one
  • decrease the video's available_inventory by one
  • create a due date. The rental's due date is the seven days from the current date.

Required Request Body Parameters

Request Body Param Type Details
customer_id integer ID of the customer attempting to check out this video
video_id integer ID of the video to be checked out

Response

Typical success response:

Status: 200

{
  "customer_id": 122581016,
  "video_id": 235040983,
  "due_date": "2020-06-31",
  "videos_checked_out_count": 2,
  "available_inventory": 5
}

Errors & Edge Cases to Check

  • The API should return back detailed errors and a status 404: Not Found if the customer does not exist
  • The API should return back detailed errors and a status 404: Not Found if the video does not exist
  • The API should return back detailed errors and a status 400: Bad Request if the video does not have any available inventory before check out

POST /rentals/check-in

Checks in a video to a customer, and updates the data in the database as such.

When successful, this request should:

  • decrease the customer's videos_checked_out_count by one
  • increase the video's available_inventory by one

Required Request Body Parameters

Request Body Param Type Details
customer_id integer ID of the customer attempting to check out this video
video_id integer ID of the video to be checked out

Response

Typical success response:

Status: 200

{
  "customer_id": 122581016,
  "video_id": 277419103,
  "videos_checked_out_count": 1,
  "available_inventory": 6
}

Errors & Edge Cases to Check

  • The API should return back detailed errors and a status 404: Not Found if the customer does not exist
  • The API should return back detailed errors and a status 404: Not Found if the video does not exist

More Optional Enhancements

These really are optional - if you've gotten here and you have time left, that means you're moving speedy fast!

Query Parameters

Any endpoint that returns a list should accept 3 optional query parameters:

Name Value Description
sort string Sort objects by this field, in ascending order
n integer Number of responses to return per page
p integer Page of responses to return

So, for an API endpoint like GET /customers, the following requests should be valid:

  • GET /customers: All customers, sorted by ID
  • GET /customers?sort=name: All customers, sorted by name
  • GET /customers?n=10&p=2: Customers 11-20, sorted by ID
  • GET /customers?sort=name&n=10&p=2: Customers 11-20, sorted by name

Of course, adding new features means you should be adding new controller tests to verify them.

Things to note:

  • Sorting by ID is the rails default
  • Possible sort fields:
    • Customers can be sorted by name, registered_at and postal_code
    • Videos can be sorted by title and release_date
    • Overdue rentals can be sorted by title, name, checkout_date and due_date
  • If the client requests both sorting and pagination, pagination should be relative to the sorted order
  • Check out the will_paginate gem

More Endpoints: Inventory Management

All these endpoints should support all 3 query parameters. All fields are sortable.

GET /rentals/overdue

List all customers with overdue videos

Fields to return:

  • video_id
  • title
  • customer_id
  • name
  • postal_code
  • checkout_date
  • due_date

GET /videos/:id/current

List customers that have currently checked out a copy of the video

URI parameters:

  • id: Video identifier

Fields to return:

  • customer_id
  • name
  • postal_code
  • checkout_date
  • due_date

GET /videos/:id/history

List customers that have checked out a copy of the video in the past

URI parameters:

  • id: Video identifier

Fields to return:

  • customer_id
  • name
  • postal_code
  • checkout_date
  • due_date

GET /customers/:id/current

List the videos a customer currently has checked out

URI parameters:

  • id: Customer ID

Fields to return:

  • title
  • checkout_date
  • due_date

GET /customers/:id/history

List the videos a customer has checked out in the past

URI parameters:

  • id: Customer ID

Fields to return:

  • title
  • checkout_date
  • due_date

video-store-api's People

Contributors

jbieniosek avatar tildeee avatar anselrognlie avatar

Forkers

tgoslee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.