Lessons: 13Length: 1.1 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

2.1 HTTP Methods and Response Codes

In this lesson, I'll introduce you to HTTP, the HTTP methods (GET, POST, etc.—also called "HTTP verbs"), and the HTTP response codes.

2.1 HTTP Methods and Response Codes

Hey folks, and welcome back to the course introducing the WP Rest API. I'm your instructor Bilal Shahid. Before we start working with the WP Rest API to retrieve and modify data, we need to familiarize ourselves with concepts including HTTP. HTTP methods and the respond codes. This information is crucial and then beginning the work we the rest API since the rest APIs are implemented using HTTP. Since this is not primarily a course about HTTP we will just take a brief look over its basic concepts. There are a few handful of materials here on text plus where you can look into the subject more closely. So first of all HTTP Hypertext Transfer Protocol and it's the backbone of the world wide web. It allows us to send information back and forth on the web, and for this purpose It has tools, the server and the client. The client initiates the request for the server to a specific URI. URI is an abbreviation for Universal Resource Identifier. And it points to a particular resource. The resource can be anything like a web page, a video clip, a song or an image file. When working the WP Rest API, the resources are things like posts, pages, users, comments, and media. The request is made of the request body and the request headers. The request headers also contain HTTP words which determine the type of the request. The four most common HTTP Verbs are GET, POST, PUT and DELETE. The GET method is the simplest of all. And it's used to read data from the server. The POST method is used to create data. And the PUT method is used to update a particular source on the server. And as the name suggests, the DELETE method is used to delete a particular resource. The safest of all these matters is the GET method since it doesn't modify any resource on the server. All three other HTTP methods modify a resource on the server. The server analyzes the request and depending on the HTTP method that was used in the request takes necessary actions. And it returns back a response to the client. That is composed of response body and the response headers. This response also contains the status code. There are several types of response codes that you might encounter than working with HTTP. The most common one is 200-OK which means that the request was successful and the server has returned a response The 201 response code usually occurs after a POST request, which means that the resource has been created successfully on the server. If the server couldn't create a response due to missing or invalid parameters. It returns the 400 bad request response code. And if the user was not authorized to perform certain action, the server returns the 401 unauthorized response code. And finally, when the user does provide authentication credentials but is not authorized to perform certain action, it results in the 403 forbidden status code. So that was a very brief overview HTTP, its matters and response codes. The understanding of these fundamental and concepts would help us when working deliberate WP Rest API. In the next lesson, we will learn about crowds and endpoints and how we could use them when performing code operations. See you in the next video.

Back to the top