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.
Last updated