5 Basic REST API Design Guidelines
5 Basic REST API Design Guidelines
MENU
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 1/12
23/10/2018 5 Basic REST API Design Guidelines
Creating and providing a state of the art API requires taking into
account:
Designing a REST API raises questions and issues for which there
is no universal answer. REST best practices are still being
debated and consolidated, which is what makes this job
fascinating.
Here are the 5 basic design guidelines that make a RESTful API:
1. Resources (URIs)
2. HTTP methods
3. HTTP headers
4. Query parameters
5. Status Codes
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 2/12
23/10/2018 5 Basic REST API Design Guidelines
1. Resources (URIs)
Names and Verbs
To describe your resources, use concrete names and not action
verbs.
For decades, computer scientists used action verbs in order to
expose services in an RPC way, for instance:
getUser(1234) createUser(user) deleteAddress(1234)
URI case
When it comes to naming resources in a program, there are 3
main types of case conventions: CamelCase, snake_case, and
spinal-case. They are just a way of naming the resources to
resemble natural language while avoiding spaces, apostrophes,
and other exotic characters. This habit is universal in
programming languages where only a nite set of characters is
authorized for names.
CamelCase
snake_case
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 3/12
23/10/2018 5 Basic REST API Design Guidelines
spinal-case
RestCase
Get an invitation to RestCase private beta
email address
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 4/12
23/10/2018 5 Basic REST API Design Guidelines
Subscribe
2. HTTP methods
As stated earlier, one of the key objectives of the REST approach
is using HTTP as an application protocol in order to avoid
shaping a homemade API.
Hence, we should systematically use HTTP verbs to describe
what actions are performed on the resources and facilitate the
developer’s work handling recurrent CRUD operations.
GET
The GET method is used to retrieve information from the given
server using a given URI. Requests using GET should only
retrieve data and should have no other e ect on the data.
HEAD
Same as GET, but transfers the status line and header section
only.
POST
A POST request is used to send data to the server, for example,
customer information, le upload, etc. using HTML forms.
PUT
Replaces all current representations of the target resource with
the uploaded content.
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 5/12
23/10/2018 5 Basic REST API Design Guidelines
DELETE
Removes all current representations of the target resource given
by a URI.
OPTIONS
Describes the communication options for the target resource.
3. HTTP headers
HTTP header elds provide required information about the
request or response, or about the object sent in the message
body.
General Header
These header elds have general applicability for both request
and response messages.
Entity Header
These header elds de ne meta information about the entity-
body or, if no BODY is present, about the resource identi ed by
the request.
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 6/12
23/10/2018 5 Basic REST API Design Guidelines
4. Query parameters
Paging
It is necessary to anticipate the paging of your resources in the
early design phase of your API. It is indeed di cult to foresee
precisely the progression of the amount of data that will be
returned. Therefore, we recommend paginating your resources
with default values when they are not provided by the calling
client, for example with a range of values [0-25].
Filtering
Filtering consists in restricting the number of queried resources
by specifying some attributes and their expected values. It is
possible to lter a collection on several attributes at the same
time and to allow several values for one ltered attribute.
Sorting
Sorting the result of a query on a collection of resources. A sort
parameter should contain the names of the attributes on which
the sorting is performed, separated by a comma.
Searching
A search is a sub-resource of a collection. As such, its results will
have a di erent format than the resources and the collection
itself. This allows us to add suggestions, corrections, and
information related to the search.
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 7/12
23/10/2018 5 Basic REST API Design Guidelines
5. Status Codes
It is very important that as a RESTful API, you make use of the
proper HTTP Status Codes especially when mocking RESTful API.
200 – OK
Everything is working
201 – CREATED
New resource has been created
204 – NO CONTENT
The resource was successfully deleted, no response body
401 – UNATHORIZED
The request requires user authentication.
403 – FORBIDDEN
The server understood the request but is refusing it or the access
is not allowed.
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 8/12
23/10/2018 5 Basic REST API Design Guidelines
RestCase
Get an invitation to RestCase private beta
email address
Subscribe
Summary
REST is not something new, REST is a return to the Web the way
it was before the age of the big application server, through its
emphasis on the early Internet standards, URI and HTTP.
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 10/12
23/10/2018 5 Basic REST API Design Guidelines
Name
Thanks :)
△ ▽ • Reply • Share ›
https://blog.restcase.com/5-basic-rest-api-design-guidelines/ 12/12