Why REST API 🚀 and modeling a perfect one 🧑🏼‍💻

Mohammad Fayaz
2 min readDec 16, 2020

In previous section we have learnt about how web servers work, scenario and things involved in HTTP request and responses. Let’s go ahead and learn why we should use REST API.

Howie Dorough Everybody GIF by BACKSTREET BOYS
  1. Business logic can be completely independent of front-end code.
  2. Can be used by multiple clients avoiding re-writing. (Mobile app, website, desktop app…)
  3. Role based access in API layer than database layer.
  4. High load can be managed with the help of HTTP proxy server and cache.

There are numerous advantages of REST API, I will list out few below. (Please comment down if I missed anything).

How we should model a perfect API?

A meaningful API is a necessary thing required for any application to grow, no matter how complex business logic we write inside it, it should be meaningful when a newbie or an external person of an organization can easily understand when he just goes through the documentation.

Checkout JSONPlaceholder a mock API as an example.

An endpoint must handle only particular work and should have very less response time. You might be thinking what would be an ideal response time? Well we couldn’t predict it and it also depends heavily on the location of the server and internet speed of the user, let’s assume everything is fine and you’re running on stable internet connection with a healthy server, then any response under 100ms might be great. That time means nothing for humans but every millisecond shoots a lot for a computer, that’s how they are designed, to be fast and effective.

Let’s design a social media back-end, considering only user and posts data.

Users

Post API

This is okay, but where is security in this? Let’s learn that in the next article of this series, the Securing REST API with JWT — OAuth 2.0 protocol. (coming soon)

Other articles in this series include

  1. Introduction to REST API and Web servers.
  2. How web servers work.
  3. Why we should use REST API. (this article)

Thank you for reading the article, feel free to follow for more such stuff and don’t forget to smash the clap button.

--

--