Difference between revisions of "REST API"

From Coder Merlin
Line 10: Line 10:
== Essential Principals ==
== Essential Principals ==


# Uniform Interface - A client should be able to query a resource, which will allow them to partake in further requests with the information that they receive. One way this may manifest itself is with similar structured URI, in that there is a uniform way in which they can be discovered without prior knowledge of their existence.
# '''Uniform Interface''' - A client should be able to query a resource, which will allow them to partake in further requests with the information that they receive. One way this may manifest itself is with similar structured URI, in that there is a uniform way in which they can be discovered without prior knowledge of their existence.
# Cacheable - It should be clear whether or not data within a response can be saved for re-use (cached), or if an equivalent request should be made in the future for similar data.
# '''Cacheable''' - It should be clear whether or not data within a response can be saved for re-use (cached), or if an equivalent request should be made in the future for similar data.
# Stateless - The client should be able to operate based solely on the data from a response, without needing prior context from stored data on the server. This means that storage of data is the responsibility of the client.
# '''Stateless''' - The client should be able to operate based solely on the data from a response, without needing prior context from stored data on the server. This means that storage of data is the responsibility of the client.
# Client-server - A REST API implements the use of a client-server architecture style to separate the interface which can take the form of different types of user interfaces from the data storage and functions on the back-end.
# '''Client-server''' - A REST API implements the use of a client-server architecture style to separate the interface which can take the form of different types of user interfaces from the data storage and functions on the back-end.
# Layered system - A layered system architecture allows for different functions of the back-end to be seperated/sandboxed so that components only have access to resources that they need
# '''Layered system''' - A layered system architecture allows for different functions of the back-end to be seperated/sandboxed so that components only have access to resources that they need


== Benefits of REST ==
== Benefits of REST ==

Revision as of 10:39, 20 August 2021

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Intro[edit]

A REST, or RESTful API is an architectural style used for API (Application Programming Interface). In a REST API, a client sends a request to the server, and the server responds with a representation (such as a JSON file), of the current state of the resource requested by the client that is stored on the server.

What is an API[edit]

An API on websites is made of code that enables two different applications to communicate with each other. They allow developers to access something from one application, even if they may be using a separate application. In summary, APIs are a form of communication between two applications, allowing their functionality to be used somewhere else.

The RESTful Criteria[edit]

REST stands for REpresentational State Transfer, and is a set of constraints that an API should comply with. These constraints are that the RESTful API must:

Essential Principals[edit]

  1. Uniform Interface - A client should be able to query a resource, which will allow them to partake in further requests with the information that they receive. One way this may manifest itself is with similar structured URI, in that there is a uniform way in which they can be discovered without prior knowledge of their existence.
  2. Cacheable - It should be clear whether or not data within a response can be saved for re-use (cached), or if an equivalent request should be made in the future for similar data.
  3. Stateless - The client should be able to operate based solely on the data from a response, without needing prior context from stored data on the server. This means that storage of data is the responsibility of the client.
  4. Client-server - A REST API implements the use of a client-server architecture style to separate the interface which can take the form of different types of user interfaces from the data storage and functions on the back-end.
  5. Layered system - A layered system architecture allows for different functions of the back-end to be seperated/sandboxed so that components only have access to resources that they need

Benefits of REST[edit]

REST is preferred over other methods because it:

Types of Requests[edit]

The HTTP protocol defines certain functions to interact with a resource. These functions are not specific to REST APIs, yet are integral in the process of creating and using a REST API. These requests are typically sent from a client to a web server or API. Four of the most common requests are outlined below.

Possible Data Formats[edit]

REST APIs can use a variety of data types to fulfill their purpose, some of which include but are not limited to:

  • .json (JavaScript Object Notation)
  • .xml (Extensible Markup Language)
  • .html (Hypertext Markup Language)
  • .xlt (Same as .xml)
  • .php (Hypertext Preprocessor)
  • .py (Python)

They may also use plain text, but out of all these options .jsos is the most popular choice because it’s easily readable by both humans and computers, but is also language-agnostic.

References[edit]

By: Mark, Aidan, and Reese