見出し画像

What is a REST API?


API stands for Application Programming Interface

REST stands for Representational State Transfer.


What does the RESTful API client request contain?

RESTful APIs require requests to contain the following main components:

Unique resource identifier

The server identifies each resource with unique resource identifiers. For REST services, the server typically performs resource identification by using a Uniform Resource Locator (URL). The URL specifies the path to the resource. A URL is similar to the website address that you enter into your browser to visit any webpage. The URL is also called the request endpoint and clearly specifies to the server what the client requires.

Method

Developers often implement RESTful APIs by using the Hypertext Transfer Protocol (HTTP). An HTTP method tells the server what it needs to do to the resource. The following are four common HTTP methods:

GET

Clients use GET to access resources that are located at the specified URL on the server. They can cache GET requests and send parameters in the RESTful API request to instruct the server to filter data before sending.

POST

Clients use POST to send data to the server. They include the data representation with the request. Sending the same POST request multiple times has the side effect of creating the same resource multiple times.

PUT

Clients use PUT to update existing resources on the server. Unlike POST, sending the same PUT request multiple times in a RESTful web service gives the same result.

DELETE

Clients use the DELETE request to remove the resource. A DELETE request can change the server state. However, if the user does not have appropriate authentication, the request fails.

HTTP headers

Request headers are the metadata exchanged between the client and server. For instance, the request header indicates the format of the request and response, provides information about request status, and so on.

Data

REST API requests might include data for the POST, PUT, and other HTTP methods to work successfully.

Parameters

RESTful API requests can include parameters that give the server more details about what needs to be done. The following are some different types of parameters:

  • Path parameters that specify URL details.

  • Query parameters that request more information about the resource.

  • Cookie parameters that authenticate clients quickly.


What does the RESTful API server response contain?

REST principles require the server response to contain the following main components:

Status line

The status line contains a three-digit status code that communicates request success or failure. For instance, 2XX codes indicate success, but 4XX and 5XX codes indicate errors. 3XX codes indicate URL redirection.

The following are some common status codes:

  • 200: Generic success response

  • 201: POST method success response

  • 400: Incorrect request that the server cannot process

  • 404: Resource not found


Benefits of REST API

Simple and standardized 
Scalable and stateless
Support cashing 

What does CRUD stand for?
Create, Read, Update, and Delete (CRUD) are the four basic functions that models should be able to do, at most.

HTTP Method 

Create → POST
Read → GET
Update → PUT
Delete → DELETE

main HTTP methods

Create → POST
Read → GET
Update → PUT
Delete → DELETE

GET http://www.example.com/customers/12345
GET http://www.example.com/customers/12345/orders
GET http://www.example.com/buckets/sample

  • GET http://www.example.com/customers/12345

  • GET http://www.example.com/customers/12345/orders

  • GET http://www.example.com/buckets/sample

  • GET http://www.example.com/customers/12345

  • GET http://www.example.com/customers/12345/orders

  • GET http://www.example.com/buckets/sample

    Read → GET
    Update → PUT
    Delete → DELETEGET
    end point of API 



Reference



https://aws.amazon.com/what-is/restful-api/

この記事が気に入ったらサポートをしてみませんか?