Hello, week-9. I want to post a blog to quickly review the API topic to learn more about REST calls. I got confused; I researched about it. It has the Understanding And Using REST APIs.
What is a REST API
API (Application Programming Interface) – A set of rules allows programs to support any other. The developer creates the API on the server and enables the client to speak to it.
The REST (Representational State Transfer) determines how the API. It is a set of rules that developers follow when they create their API. One of the rules states that one should get data (called a resource) when linking to a specific URL. Each URL made a request, while the data sent back to is called a response.
The Anatomy Of A Request #
It’s important to know that a request with four points:
- The endpoint
- The method
- The headers
- The data (or body)
The endpoint – URL that requests for (root-endpoint/?). The root-endpoint is the starting point of the API that is ordering.
The path determines the resource request. For example, it is like an automatic answering machine. That asks to press 1 for service, press 2 for another service, 3 for yet another service, and so on.
The Method
The method is the type of request sent to the server:
- GET – Request to get a resource from a server. It will perform a `GET` request; the server looks for the requested data and sends it back.
- POST – Request to create a new resource on a server. It performs a `POST` request, the server creates a new entry in the database and tells whether the creation is successful.
- PUT & PATCH – Requests to update a resource on a server. If performing a `PUT` or `PATCH` request, the server updates an entry in the database and tells whether the update is successful.
- DELETE – Request to delete a resource from a server. If performing a `DELETE` request, the server deletes an entry in the database and tells whether the deletion is successful.
These methods provide meaning for the request made. Perform steps: Create, Read, Update and Delete (CRUD).
The HEAD: it used to provide information to both the client and server. It has many purposes, such as authentication and giving information about the body content. It can find a list of valid headers on MDN’s HTTP Headers Reference.
The Data – contains information sent to the server. It only used POST, PUT, PATCH, or DELETE requests.
From the blog Andrew Lam’s little blog by Andrew Lam and used with permission of the author. All other rights reserved by the author.