REST API - Acid Dragons

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Visual representation of REST API Flow

Background[edit]

Introduction[edit]

APIs are used all day every day. Every TikTok that’s watched, every Instagram video liked, and every totothetoilet Twitch video streamed uses an API. Just like there’s a vast amount of programming languages, there is a vast amount of APIs to choose from each proving its own pros and cons. Rest API is one of the most popular APIs and is widely used. Rest API involves a great amount of flexibility and takes use of existing protocols, this means that developers do not need to download an excessive amount of libraries or software when creating a REST API.

In this wiki page, we will describe what an API is, what Rest API is, as well as steps to create your very own Rest API.

What is an API[edit]

A.P.I. (Application Programming Interface) is a set of definitions and protocols that allow communication between 2 devices. The concept is similar to a text message. You type in a phone number, then someone else’s phone receives that text. By using API you can send information or receive it without knowing all the details surrounding what is done. It simplifies processes without having to change much code. API is the set of rules and definitions used to define information. Another example would be checking the weather on your phone. In order to receive accurate weather information, an app might ask for your location in order to give you information on the area you are in. Party 1(Person) asks for weather, Party 2(Weather app) requires Location, Party 1(Person) gives location, and Party 2 (Weather app) sends information for the weather. When Party1 asks for the weather, a protocol in the API sends a notification for your location data. When Party 1 sends location data, Party 2 compares it with the server until a location match is found. Once found, it sends the weather to Party 2 and then subsequently to Party 1.

What is REST API[edit]

Visual representation of REST API Flow

A rest API, sometimes referenced as RESTful APIs, is an API that follows the design principles of the representational state transfer architectural style or better known as REST. So what does that actually mean? REST APIs can be developed using any language with the only restriction being the REST design principles must be met. There are a total of six design principles that we’ll be going over.

Uniform Interface[edit]

Uniform Interface simply put is making sure that all API requests should look the same regardless of the origin.

A Client-Server Decoupling[edit]

A client-server decoupling is virtually what the name says. It’s the requirement to make sure that the client and server applications are completely independent of each other.

Statelessness[edit]

The third principle is statelessness, meaning all the requests made must have all the necessary information to process them. This goes both ways - no unnecessary information such as information for the server-side sessions is required to be given.

Cacheability[edit]

The fourth principle is Cacheability stating that resources should be able to be cacheable on the client or server-side as well as server responses needing to provide information on whether caching is allowed for the delivered resource.

Layered Architecture[edit]

The fifth principle is having a layered architecture. Rest APIs have calls and responses that go through a multitude of layers so it would be unwise to assume that the client and server applications are directly connected to each other. REST APIs have to be developed to make sure that the client and server cannot be aware of whether they communicate with the end application or intermediary.

Code on Demand[edit]

The last principle is to code on demand which can be considered optional given the circumstances. REST API usually sends static resources but sometimes contains executable code like (JAVA applets). Under the circumstance the REST API contains executable code, the code should only be run on-demand.


How does a REST API work?[edit]

Rest API’S communicate given HTTPS requests to be able to perform simple standard functions such as creating, reading, updating, etc.

Steps to create Rest API[edit]

Visual representation of REST API Flow
  • Create an HTTP Method. Some examples of HTTP Methods are POST, GET, PUT, PATCH, DELETE. POST is an HTTP Method that creates the request, GET is a method that reads the request, PUT is a method that Updates the request. PATCH is a method that modifies the request while DELETE, deletes the request after it's done.
  • Request & Response HTTP Headers. The two types of HTTP headers required to use the REST API are the Request header and the Response header. The request headers contain information about the client that is requesting as well as what data needs to be gathered. The Response HTTP Header contains information about the server location of the request as well as which server is providing the information.
  • Next, the query parameters need to be established. The query parameters can control and manipulate the data that is being returned after the request. One of the parameters can be to control the set of data that is being returned. The query parameters can also control the setting properties for the set of the data for the set of data that was returned. One way the query parameters can manipulate the data is to change the order of information. This may be beneficial to your code by making it more efficient.
  • HTTP bodies are used to determine what information needs to be requested. This is often done with the HTTP Headers. The most common causes of HTTP bodies are dictionaries. By sending the key in the request, the request will be able to get the value associated with the key and return the information back to the client.


Conclusion[edit]

REST API, or even just API in general is such an amazing feature. They offer scalability, flexibility, portability, and independence. Because of that, so many companies and websites, even those big companies like Amazon, Facebook, Google, Twitter,.. use REST API.

References[edit]