How to use APIs with JavaScript

An API, or application programming interface, is kind of like a coding contract: it specifies the ways a program can interact with an application. For example, if you want to write a program that reads and analyzes data from Twitter, you'd need to use the Twitter API, which would specify the process for authentication, important URLs, classes, methods, and so on.

For an API or web service to be RESTful, it must do the following:

  1. Separate the client from the server
  2. Not hold state between requests (meaning that all the information necessary to respond to a request is available in each individual request; no data, or state, is held by the server from request to request)
  3. Use HTTP and HTTP methods (as explained in the next section).

There are some other requirements, but they're beyond the scope of this lesson.


Check out the code in the editor. This is an example of the kind of information we can get from an API! (It's in a format called JSON, which we'll explain soon.)

Click Save & Submit Code to continue.