JS-151-API
  • JavaScript Library
  • 02-DOM-Manipulation
    • Overview
    • DOM Explained
    • Example Setup
    • Selecting Elements
    • Events
    • Complete Example
  • 03-API Fundamentals
    • 0-Getting Started
      • Welcome
    • 1-Intro-To-APIs
      • Intro
      • Client
      • Requests
      • JSON
      • API Endpoints
      • Server
      • Response
      • Statelessness
      • REST
    • 2-Asynchronous-Programming
      • Intro
      • Callbacks
      • Promises
      • Promises Continued
      • Chaining Promises
    • 3-Fetch
      • Fetch Intro
      • Star Wars
        • Star Wars API
        • Star Wars Setup
        • Star Wars JS
      • Random Photo
        • Unsplash
        • Unsplash Setup
        • Unsplash JS
    • 4-Apps
      • 01-New York Times
        • 00-App Intro
        • 01-HTML/CSS/API Key
        • 02-Variables
        • 03-Event Listeners
        • 04-fetchResults
          • 01-fetchResults()
          • 02-preventDefault()
          • 03-fetch() method
          • 04-Dates
        • 05-displayResults
          • 01-Logging JSON
          • 02-Working with JSON
          • 03-Link Display
          • 04-Results Navigation
          • 05-Results Update
          • 06-Keywords
          • 07-Images
        • 06-Pagination
          • 01-Pagination Intro
          • 02-Pagination Functions
        • 07-Next Steps
      • 02-YouTube
        • html
        • youtube.css
        • youtube.js
      • 03-GoogleMaps
        • Setup
        • HTML and CSS files
        • API Key
        • JS Setup
        • Adding Your Location
        • Listeners
        • Custom Options
Powered by GitBook
On this page
  • What is REST?
  • The Rules of REST
  • Our Use of APIs
  1. 03-API Fundamentals
  2. 1-Intro-To-APIs

REST

What is REST?

REST stands for “Representational State Transfer”, and was introduced and defined by Roy Fielding in his 2000 doctoral shape. It is a set of rules that, if developers want their API to be RESTful, they follow when creating their API. A lot of the properties of APIs that we've talked about are actually specific to RESTful APIs. Most APIs that developers create and use are RESTful.

The Rules of REST

  • Client and server are separate: this is what we described in the above chapters!

  • Stateless: no client context is stored server-side in between requets, all information needed for each request has to be given each time by the client. For example, if I'm making multiple API calls about a user, I need to specify which user each time, the server doesn't store anything between requests. Again, we just talked about this in the previous chapter.

  • Cacheable: Responses from the server have to let the client know if they are cacheable.

  • Layered system: Can have an intermediary server to improve load balances and speed when more users are using the system.

  • Code on demand: This is optional. The ability to pass code from server to client, to allow the client to run it.

  • Uniform interface: This is fundamental to REST

    • Identification of resources: All resources have an identifier, a separate way of conceptualizing those resources, that are not simply the resource themselves. So the resource can be in JSON or any format, which is not necessarily the structure or type of the resource on the server.

    • Self-descriptive messages: Each message includes enough information to know what to do with it, without needing any other outside information. So for example, it'll tell you it's JSON so the client can interpret it.

    • Resource manipulation through representations: The client has enough information to edit and delete the resource.

Our Use of APIs

Many APIs that are in use today are, at least partially, based on REST principles. Since 2000, most people have realized some of the advantages of RESTful design, and utilized at least some of the principles. You'll often hear REST referred to in the same breadth as API. The use of the word REST is a little overused, but basically they're often thought of hand in hand. Until recently, with the development of GraphQL APIs, REST was kind of the default. GraphQL uses some of the same ideas, but a much different format. You can worry about that later, it's just good to know what REST is.

PreviousStatelessnessNext2-Asynchronous-Programming

Last updated 7 years ago