DEV Community

Ben Greenberg
Ben Greenberg

Posted on

A Brief Introduction to REST APIs

Even if you have no idea what REST means, you have been interacting with it throughout the web for quite some time. Now let's take some time to explore what REST means and what a REST API is. REST stands for "REpresentational State Transfer". The concept was introduced to the world in a 2000 doctoral dissertation by Roy Fielding. REST is a way of managing the client-server relationship and strives for speed and performance by incorporating re-usable components. What are the basic features of a RESTful architecture:

  1. Stateless: Client data is not stored on the server between interactions and the session is stored client-side (typically in session storage).
  2. Client<->Server: There is a separation of concerns between the frontend (client) and the backend (server). They operate independently of each other and both are replaceable.
  3. Cache: Data from the server can be cached on the client, which can improve performance speed.

In addition to these three fundamental features of REST, there is also a uniform approach to the composition of base URLs. This allows for a standardization of service, which prior to the introduction of REST, did not exist. For example, a GET request to /dogs, should yield all the dogs in the database, whereas a GET request to /dogs/5 would render the dog with an ID of 5. Similarly, REST utilizes standard methods like GET, PUT, DELETE and POST to perform actions.

Thus, a RESTful API would be one that is a) stateless, b) separates concerns between client-server, c) allows caching of data client-side and d) utilizes standardized base URLs and standardized methods to perform actions to manipulate, add or delete data.

Furthermore, it has become common practice for REST APIs to also return data in a standard format. The most popular format nowadays is JSON (JavaScript Object Notation). The standardization of the formatting of the data is another step towards uniformity in the way resources are interacted with on the web allowing for developers to solve problems and not spend their time in configuration of the basic architecture.

When requesting data from an API you might get back something like this:

{
    title: "This is JSON",
    content: [
        chapter: "1",
        page: "200",
        firstParagraph: "This is what JSON looks like when it is returned from an API."
    ],
    author: "Ben Greenberg",
    source: "dev.to"
}
Enter fullscreen mode Exit fullscreen mode

This allows for easy access of that data within the JSON with something like data.title, which would return "This is JSON".

Where can you find RESTful APIs? Everywhere! Twitter. Google. Ebay. So many of the popular services we take advantage of daily utilize a RESTful architecture for their API service. Now you can also.

Latest comments (8)

Collapse
 
frankkubis profile image
Frank Kubis • Edited

Sorry but, this is NOT REST, its just HTTP with JSON response. This does not mean REST. There is no hypermedia in your example.

Take a look at fowlers article: martinfowler.com/articles/richards...

Collapse
 
bengreenberg profile image
Ben Greenberg

Yes, hypermedia is an element of REST as are HTTP verbs, statelessness, etc. Thanks for the article mention.

Collapse
 
andychiare profile image
Andrea Chiarelli

Where is hypermedia? An API cannot be called RESTful if it doesn't implement HATEOAS (Hypermedia As The Engine Of Application State)
See roy.gbiv.com/untangled/2008/rest-a...

Collapse
 
bengreenberg profile image
Ben Greenberg

Yes, you are correct. I wrote this a while back in October and forgot to include hypermedia in addition to the elements of statelessness, caching, etc. Thanks for the reminder.

Collapse
 
carywreams profile image
Cary Reams

Are RESTful APIs inextricably bound to HTTP Verb implementations of the standard GET, PUT, DELETE, and POST methods ?

More:
I get using HTTP Verbs to execute RESTful requests when managing static documents on a web server. No argument. Clear value proposition.

However, I'm wondering about embedding a RESTful API within the payload of a POST or GET request as appropriate, when modifying a database as opposed to documents or some other resource directly available to Apache, IIS, nginx, etc.

Collapse
 
ryhenness profile image
Ryan

Cool article! I like the overview. :) Maybe you could write something about using Postman as a supplementary post!

Collapse
 
peter profile image
Peter Kim Frank

Nice article, @benhayehudi ! Really enjoying these "Brief Introductions to X" and "What's the deal with Y" articles.

Collapse
 
bengreenberg profile image
Ben Greenberg

Thanks! It's fun to write them and glad to have this forum to share them!