REST API⚓︎
REST API
, also known asRESTful API
, is a web service that allows various clients including browser apps to communicate with a server.
Basic Knowledge⚓︎
REST⚓︎
REST
?
-
Definition: Representational State Transfer. It describes a way how a clients and servers interact with each other.
-
Property: REST conforms to specific architectural constraints, like stateless communication and cacheable data.
Operating principle
REST
communication typically bases on HTTP protocol (but that isn't a requirement). Requests are made to a resource URI, possibly containing additional request data. Replies can be anything: HTML
, XML
, JSON ([RFCs 8259](https://www.rfc-editor.org/rfc/rfc8259))
, CSV
, plain-text
, or even raw binary data
.
Benifits
- Scalability
- Independent
- Generality
- Latency
- Security
- Legacy
- Stateless
REST over HTTP (request to backend)⚓︎
notes
In computer programming, create
, read
, update
, and delete
(CRUD operations) are the four basic operations of persistent storage.
Each letter in the acronym may be mapped to a Hypertext Transfer Protocol (HTTP) method:
CRUD | HTTP | Details |
---|---|---|
Create | POST , PUT if we have id or uuid |
submits new data to the server. |
Read | GET |
retrieves resources. |
Update | PUT , PATCH |
updates existing data (specific one). |
Delete | DELETE |
removes data. |
Example
We can refer to the code described in Express.js to learn how to implement CRUD
operations using Javascript
.
REST Response (response to frontend)⚓︎
Number | Meaning |
---|---|
2XX | Success |
4XX | Client Problem |
5XX | Server Problem |
Implementation Sketch⚓︎
REST API⚓︎
REST API
?
API
: application programming interface.
To access a REST service, the client needs to know the REST API
that the service if offering, so there must be documentation, and you need to write code according to that documentation.
With OpenAPI
this step is automated. With OpenAPI
, there exists a machine parseable file that explains to computers how a REST API
works. It tells the code what requests exist and what replies to expect.
Open API
?
Suppose you have an OpenAPI implementation and an OpenAPI description file of a REST API. In that case, you can feed that description file to the OpenAPI implementation, and this implementation now knows how to use the REST API, it can generate human-readable documentation for you, or it could even auto-generate code to use the REST API in different languages.
References:⚓︎
Created: December 4, 2022 01:47:38