Vous êtes sur la page 1sur 1

4/9/2020 REST verbs and status codes - Hands-On RESTful Web Services with Go - Second Edition

 Hands-On RESTful Web Services with Go - Second Edition

PREV NEXT
⏮ ⏭
Characteristics of REST services GET
  🔎

REST verbs and status codes


REST verbs specify an action to be performed on a specific resource or a
collection of resources. When a request is made by the client, it should send the
following information in the HTTP request:

The REST verb

Header information

The body (optional)

As we mentioned previously, REST uses the URI to decode the resource to be


handled. There are quite a few REST verbs available, but six of them are used
particularly frequently. They are presented, along with their expected actions, in
the following table:

REST
Action
Verb

Fetches a record or set of resources from the


GET
server

OPTIONS Fetches all available REST operations 

POST Creates a resource or a new set of resources

PUT Updates or replaces the given record

PATCH Modifies the given record

DELETE Deletes the given resource 

The status of these operations can be known from HTTP status codes. Whenever
a client initiates a REST operation, since REST is stateless, the client should
know a way to find out whether the operation was successful or not. For that
reason, HTTP responses have a status code. REST defines a few standard status
code types for a given operation. This means a REST API should strictly follow
the following rules to achieve stable results in client-server communication.
There are three important ranges available based on the types of error. See the
following table for error ranges:

Status
Number
Code Action
Range
Type

 The 2xx family is used for


Success 200 - 226
successful responses.

400 - 499 The 4xx family is used for


(client), indicating client errors. The 5xx is
Error
500 - 599 for server failures to process the
(server) request.

The 3xx family is for URL


Redirect 300 - 308
redirection.

The detail of what each status code does is very precisely defined, and the overall
count of codes increases every year. We mention the important ones in the
upcoming section.

All requests to REST services have the following format. It consists of the host
and the API endpoint. The API endpoint is the URL path that is predefined by the
server. It can also include optional query parameters.

A trivial REST API URI looks like the


following: http://HostName/APIEndpoint/?key=value(optional)

Let's look at all the verbs in more detail. The REST API design starts with the
defining of operations and API endpoints. Before implementing the API, the
design document should list all the endpoints for the given resources.

In the following section, we carefully observe the REST API endpoints using
PayPal's REST API as a use case.

Settings / Support / Sign Out


© 2020 O'Reilly Media, Inc. Terms of Service / Privacy Policy
PREV NEXT
⏮ ⏭
Characteristics of REST services GET

You have 2 days le in your trial, Reddychan. Subscribe today. See pricing options.

https://learning.oreilly.com/library/view/hands-on-restful-web/9781838643577/85f14d60-d4bf-447a-87a9-0cc4b14a62d6.xhtml 1/1

Vous aimerez peut-être aussi