A Look at HTTP Request Methods

Having set up our server, we are ready to start building our API. The routes are basically what constitute the actual API.

We will first look at HTTP request methods (sometimes referred to as HTTP verbs), then apply them to our API using a simple todo list example. We will look at five major ones:

  • GET: Requests a representation of the specified resource. Requests using GET should only retrieve data, and should not be used to make changes to resources.
  • POST: Is used to submit an entry to a specified resource, often causing a change of state.
  • PUT: Replaces all current representations of the target resource with the request payload.
  • DELETE: Deletes the specified resource.
  • PATCH: Used to apply partial modifications to a resource.

In the following exercises, we're going to rewrite our previous code where we had hardcoded our data so that we can work with real and dynamic data coming directly from the database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset