RESTApi Cheat Sheet

A Software › Nope cheat sheet in English by singular

REST (Representational State Transfer) is an architectural style for building web services. A RESTful API (Application Programming Interface) is a web service that adheres to the REST constraints and allows developers to interact with the application via HTTP(S) requests.

2,788 views 761 downloads 12 Apr 2023 History

Methods

GET
Retrieve a resource or a collection of resources
POST
Create a new resource
PUT
Update an existing resource
PATCH
Update a part of an existing resource
DELETE
Delete an existing resource

HTTP Request Headers

Accept - specifies the format of the response (e.g. applic­ati­on/­json)
Author­ization - provides authen­tic­ation inform­ation
Conten­t-Type - specifies the format of the request body (e.g. applic­ati­on/­json)
If-Match - ensures that the resource hasn't been updated since the client last retrieved it
If-Non­e-Match - ensures that the resource hasn't been modified since the client last retrieved it

HTTP Status Codes

200
OK - Successful request
201
Created - Resource succes­sfully created
204
No Content - Successful request but no content to return
400
Bad Request - Invalid request data
401
Unauth­orized - Authen­tic­ation required
403
Forbidden - Author­ization required
404
Not Found - Resource not found
500
Internal Server Error - Server error

HTTP Response Headers

ETag - provides a version number for the resource
Location - provides the URI for the newly created resource
Conten­t-Type - specifies the format of the response body (e.g. applic­ati­on/­json)

Resources URI

/resources
Retrieve all resources
/resou­rce­s/{id}
Retrieve a single resource by ID
/resou­rce­s?f­ilt­er=­value
Retrieve resources with a specific value
/resources
Create a new resource
/resou­rce­s/{id}
Update an existing resource by ID
/resou­rce­s/{id}
Delete an existing resource by ID

API Best Practices

Use HTTP methods correctly
Use plural nouns for resource names
Use nouns for endpoint names
Use query parameters for filtering and sorting
Use error codes consis­tently
Use versioning to manage changes
Use pagination for large data sets
Provide API docume­ntation and examples

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.