Learn about RESTful API

Tram Ho

RESTful API is a standard used in designing APIs for web applications to manage resources. RESTful is one of the most commonly used API designs today so that different applications (web, mobile, webserice …) can communicate with each other.

Structure of RESTful API

API

API stands for Application Programming Interface which is a set of definitions, protocols, and subroutine tools to build for building software and applications. Simply put, an API is a software intermediary that allows two applications to communicate with each other. The API can return the data that you need for your application in common data types like JSON or XML. With API, you can easily access and retrieve data from the server, present them on your software application or website. Up to now, the API has evolved with various types of applications and software. The latest generation of web / app API can be applied to any system from databases, operating systems, web-based systems, libraries or even computer hardware.

REST & RESTful

REST or ReST (REpresentational State Transfer) is a form of data structure transformation proposed by computer scientist Roy Thomas Fielding in 2012.

REST is a type of architecture used for communicating between computers (personal computers and web servers) in managing resources on the internet.

REST is used a lot in the development of Web Services applications that use the HTTP protocol in communication through the internet. Applications that use this REST architecture are known as RESTful development applications. A RESTful API is simply an API that complies with REST principles and constraints.

REST consists of 3 basic parts such as: external server, API server and client server. In it, the client can be anything, web-based application, library or even various software of a computer software.

REST allows clients to access the API server and execute commands to retrieve, modify, or delete data from the external server. Programmers can freely access and edit data from the server without knowing how the system works.

How REST works

When working with the server, there will be 4 essential activities:

  • Get data in a certain format (JSON)
  • Create new data
  • Updating data
  • Delete data

REST works mainly on the HTTP protocol. Each of the four basic operations above will use its own HTTP methods:

  • POST (CREATE): Create a new Resource.
  • GET (READ): Returns a Resource or Resource list.
  • PUT (UPDATE): Update, replace information for Resource.
  • DELETE (DELETE): Delete a Resource.

REST is a unified architecture that helps design websites so that resources can be easily managed. It is not a rule you must follow but simply a proposed architecture and this architecture is being used very popularly because of its simplicity, ease of understanding and superiority. With web applications designed using RESTful, you can easily know the URL and HTTP method to manage a resource.

REST constraints

  1. Client-server architecture: Server will be a small set of services that handle requests from clients, the separation increases the client’s flexibility as well as the server’s scalability while ensuring communication.
  2. Stateless: Server and client will not save each other’s state, each request and response will contain full information, separate from each other, this makes the system easy to develop and expand.
  3. Cacheability (capable of caching): The responses can be retrieved from the server’s cache to help reduce processing time, the requests must ensure uniqueness so that the response is not confused with other requests.
  4. Layered system: The system is divided into many layers, the communication of a layer is carried out only with the layer above and below it, load balancing capabilities and data cache. data in the system will also be improved.
  5. Uniform interface (standardized interfaces): This is the most important constraint of a REST system. To ensure this constraint, the system focuses on handling resources. Each resource will be identified (identified) by a unique URI (Uniform Resource Identifier).

Advantages of REST

  • REST also has the advantage of using a stateless (stateless) protocol. This system does not use sessions, cookies, does not need to know that information in every request to an external server. This helps REST reduce the load on the external server, improving working efficiency.
  • Variability: for systems that need constantly changing resources, using REST with simple request creation makes things simpler.
  • Extensibility: REST systems are highly scalable thanks to the separation of components and pre-defined communication conventions.
  • Flexibility: The standardized interface makes the system more flexible, can be used for many different platforms, mobile, web, …
  • Transparency: in the communication between components, requests become very clear and easy to understand.

Disadvantages of REST

  • REST Only works on HTTP protocols.
  • The advantage of using HTTP constructs is also a limitation. Because HTTP restrictions also become limitations of the REST architecture. For example, HTTP does not store state information between cycles when responding a request, and as such REST-based applications fall into a state of unknown state and all state management tasks must be machine-driven. guests perform.

Conclude

In short, the above article is about REST and RESTful API knowledge I learn. In the article, there must be many shortcomings, hope everyone can contribute to the article more complete.

Share the news now

Source : Viblo