Simplifying REST APIs

Shubham Gautam
4 min readJan 12, 2021

If you’ve ever booked an Uber, you’ve probably seen the embedded Google Map that shows you the live location of the car. Ever wondered how is it done? Is Uber allowed to access google’s database or is there any hidden mechanism? Well, the short answer for this query is ‘through APIs’.

API is a common yet not so common term. So, before diving into the concept of REST APIs, let’s understand what does API exactly means and why does it matter?

API

API stands for Application Programming Interface. It is a set of programming codes that enables data transmission between one software product and another. The developer creates the API on the server and allows the client to talk to it. It’s like a cog that allows two systems to interact with each other.

Application Programming Interface

Too much of a technical definition? Let’s simplify it using an analogy. Imagine that you’re sitting in a restaurant with a menu of choices to choose from. You want to send your order request to the kitchen so that they can prepare your order, but how do you do that?

Yes! You’d ask the waiter (messenger) to send your order (request) to the kitchen (server) and bring it for you (response). That’s what an API does, they help the client to talk with the server. It’s a mediator who takes your request and delivers the response back to you.

API Analogy

Now that we’ve understood APIs, let us talk about the REST APIs.

REST stands for Representational State Transfer and they are used to determine how the APIs would look like. REST is not a standard protocol, but an architectural style that uses HTTP requests to access and use the data. It is a set of rules that developers follow when they create their API(s).

For an API to be considered RESTful, it has to conform to these criteria (click each constraint to read more about it):

  • Uniform Interface — There should be a uniform way of interacting with a given server irrespective of device or type of application (website, android, iOS).
  • Stateless — Stateless means that each time the client access a resource, the API provides the same response. It doesn’t keep into consideration any last request made.
  • Cacheable — Caching with REST is similar to caching of web pages. The browser uses the last-modified-time value in the HTTP headers to determine if it needs to get the resource again.
  • Client-Server — REST services follow a defined server-client architecture. The client should be able to fetch data without taking into consideration the storage or database and the server should be able to provide data irrespective of the user interface.
  • Layered System — The REST architecture needs to be composed of multiple layers which are independent of each other.
  • Code on Demand (optional) — Servers can also provide executable code to the client.

One of the unique aspects of REST is that REST APIs focus on resources (that is, things, rather than actions) and ways to access the resources. Resources are typically different types of information.

Each URL is called a request while the data sent back to you is called a response.

Request methods in REST APIs:

Since REST APIs use HTTP methods to talk over the network, here are some of the most-commonly-used request methods:

  1. GET — To retrieve a resource (data). It is a read-only method.
  2. POST — To create a resource. It is used to receive data from the client and submit it to a particular resource.
  3. DELETE — To delete a resource.
  4. PUT — To update the specified resource by replacing the existing data.

The advantages of REST APIs:

Some of the advantages of using REST APIs are:

  1. They are scalable. In other words, the REST APIs can quickly handle the increasing amount and variety of requests.
  2. They are independent of the language being used and can easily serialize data in JSON or XML format.
  3. High loads can be easily managed with the help of HTTP proxy server and cache.
  4. They are cleaner and easy to understand.

Examples of REST APIs:

  1. Spotify — Spotify’s web API allows clients to request information about artists, songs, albums, and playlists on its platform.
  2. Twitter — Twitter’s API allows clients to write, post, and share tweets. This API is largely used for data analysis and many other machine learning purposes.

Thank You.

--

--