Giter Club home page Giter Club logo

restful-api-exercises's Introduction

Understanding REST

Now that you've read these over-complicated explanations of REST (though they are the best ones we could find), this exercise will show you that it isn't so complicated.

In communicating with APIs, every piece of information is a resource. These are the nouns of your program.

There are only a few verbs that you can perform on these resources:

  • GET
  • POST
  • PUT
  • PATCH

Lets not worry about PUT and PATCH for the time being. There's nothing scary about them, we just won't need them at first.

We have worked with the Giphy API. For this API the nouns were GIFS. But there was more to it than that! As you recall, there were trending GIFS, GIFS by keyword, etc. We could GET these GIF objects, and that would return a JSON object with a bunch of information for us to do whatever we wanted with.

If we wanted trending GIFS, we went to one URL. If we wanted GIFS by a keyword, we went to another. The way that this is set up is the essence of REST.

Let's look at a concrete example:

Say we want to create our own RESTful API that for comedy video objects, much like our GIF objects.

We want urls that can return the following resources:

  1. all videos in our database
  2. an individual video based on the video ID
  3. info on all comedians
  4. info on a specific comedian based on comedian ID
  5. all videos by a specific comedian
  6. specific video by a specific comedian

In Express this will be done using JavaScript, but we will be PSEUDOCODING to remove the element of syntax from the equation so we can focus on REST itself. Here is pseudocode of routes for the above API:

// My pseudo-code routes:

GET ALL VIDEOS "/videos"

GET VIDEO BY ID "/vidoes/:id"

GET ALL COMEDIANS "/comedians"

GET COMEDIAN: "/comedians/:id"

GET ALL VIDEOS BY COMEDIAN "/comedians/:id/videos"

GET VIDEO BY COMEDIAN "/comedians/:id/videos/:id"

Note: In the above example any code preceded by a colon is a variable which would be filled in by specific information in the real requests. This is typical syntax in talking about variables in routes.

That's all there is to it!

Now its your turn.

Say we want to create an API similar to the one above, that returns data about icecream. We need to be able to get information about specific flavors, as well as all of the flavors we have in our database. We also want to get some flavors by category, like "fruity", "gluten free", or "chunky". Finally we want to add one POST route that allows users of our API to add new flavors!

Write Pseudocode like the above. Be creative, and follow RESTful conventions and best practices.

Deliverables

Fork and clone this repo. Submit your pseudocode in a markdown or text file by making a pull request on this repository.

restful-api-exercises's People

Contributors

cofauver avatar

Watchers

James Cloos avatar  avatar

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.