Skip to content

Instantly share code, notes, and snippets.

@megstang
Last active December 5, 2022 15:18
Show Gist options
  • Save megstang/61da49beb3ab1c6243a412aeb001889c to your computer and use it in GitHub Desktop.
Save megstang/61da49beb3ab1c6243a412aeb001889c to your computer and use it in GitHub Desktop.
Building API Tutorial Extension

Tutorial Extension

Do the following with your small group:

  1. Review parts 1-7 together

  2. If you all got through the section about versioning, review that together as well. If not everyone did it, work on it together.

  3. Create an endpoint to sell a book

    • request: PATCH /api/v1/books/1/sell
    • response:
          {
    	  "id": 1,
    	  "title": "The Moving Finger",
    	  "author": "Cortez Shields II",
    	  "genre": "Fable",
    	  "summary": "Omnis vitae fugiat. Nesciunt eos eius. Aperiam atque nihil.",
    	  "number_sold": 2,
    	  "created_at": "2022-10-17T15:10:51.614Z",
    	  "updated_at": "2022-10-17T15:10:51.614Z"
          }
    • Assuming number_sold was originally 1
  4. Update your GET /api/v1/books endpoint to get books with a certain reading level

    • request: GET /api/v1/books?reading_level=3
    • response:
    [
      {
          "id": 1,
          "title": "The Moving Finger",
          "author": "Cortez Shields II",
          "genre": "Fable",
          "summary": "Omnis vitae fugiat. Nesciunt eos eius. Aperiam atque nihil.",
          "number_sold": 2,
          "reading_level": 3,
          "created_at": "2022-10-17T15:10:51.614Z",
          "updated_at": "2022-10-17T15:10:51.614Z"
      },
      {
        "id": 2,
        "title": "Dulce et Decorum Est",
        "author": "Cornell Schaefer",
        "genre": "Folklore",
        "summary": "Est distinctio autem. Adipisci maxime eligendi. Repudiandae quas sed.",
        "number_sold": 5,
        "reading_level": 3,
        "created_at": "2022-10-17T15:10:51.617Z",
        "updated_at": "2022-10-17T15:10:51.617Z"
      },
      ...
    ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment