Full-Stack Web Development with Vue.js and Node

(singke) #1
Introducing REST APIs Chapter 4

PUT


The PUT request is used to create or update a record. It creates a new record if the resource


does not exist yet and updates the existing record if the resource already exists. The
equivalent CRUD operation is update(). It replaces the existing representation of the


resource. An example URL for a PUT request is as follows:


PUT http://www.example.com/users/

DELETE


This is used to remove resources from a collection. The equivalent CRUD operation is
delete().


An example URL for a DELETE request is as follows:


DELETE http://www.example.com/users/{user_id}

HTTP status codes


Status codes are the part of a response made by the server for a request made to that server.
It indicates the status of a request, irrespective of whether it got successfully executed or


not. The status codes have three digits. The first digit represents the class or the category of
that response. The HTTP status codes range from 100-500. We will be covering some of the


major status codes in this section.


2XX codes


The 200 range status code is the success range for any request in the API. Within the 200


range, there is a lot of code that represents different forms of success. Explained here are a
few of the many status codes that are available:


200 OK: This response is the standard one. It is just a representation of the
request being successful. This status code also returns the resource on which the
request was executed.
Free download pdf