Monday, December 12, 2022

50/365: RESTful API

 An application programming interface is a way for two computers to talk to each other. Instead of going to a website with a browser, a programmer can interact with the website's API using code to request the raw JSON data. Most APIs in the world are RESTful, which means they follow rules allowing for Representational State Transfer. A RESTful API organizes its information into various Uniform Resource Identifiers, or URIs. These are similar to URLs, and a client can get data about that resource by getting a request about that endpoint via HTTP. These requests follow a specific format, using an "HTTP" verb followed by the URI. These verbs signal your intent with the resources. Commonly used is GET, meaning you want to read the data, whereas POST means you want to create a new resource. Headers contain metadata about the request, such as authorization, and a body of data. The server processes the transaction which usually means querying a database. This is formatted into a repones message with a status code. A code beginning with 200 mean things are OK, 400 means something was wrong with the request, and a 500 means the server failed. After the response header, the body contains the response payload formatted in JSON. It is important to realize this architecture is stateless, meaning the two parties do not need to store any information about each other and every request and response is independent of all other conversation. All together this leads to web applications thar are predictable and reliable. The most popular tool to build your own RESTful API is NextJS, which I intend to learn soon. 

No comments:

Post a Comment

190: Sablier

 The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...