
HTTP contd..
1.5 HTTP Methods
The first line of the request message is called the request line and it contains HTTP methods. If you’re used to coding in JavaScript you might well be aware that “methods” are functions attached to objects. In simpler terms these “methods” are “actions”.
The role of the method in the request line is to specify what “action” the client [i.e. the browser] has requested. Now on to the most common methods you will typically use in web dev.
1.6 GET
The GET method is the most commonly used in apis and websites. It is used to request information from a specified URL. For example:
GET http://www.amazon.com/books
1.7 POST
The POST method is used to update an existing resource. This method will request that the server accept the data enclosed within the body of the request message
1.8 PUT
The PUT method will request the server to store the contents of the request body at the specified URL. For example:
PUT/hello.html HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.kauress.me Accept-Language: en-us Connection: Keep-Alive Content-type: text/html Content-Length: 180
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>
The above HTML will be PUT at the specified resource hello.html
1.8 DELETE
The delete method is used to delete a resource at a specified location. For example:
DELETE /hello.html HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.kauress.me Accept-Language: en-us Connection: Keep-Alive Content-type: text/html Content-Length: 180 In the above example, the file hello.html is deleted.
1.9 Response Status Codes
When a request message comes to a server by a browser, the server will interpret the message and carry out whatever action needs to be taken depending on the method used. After which the server sends a response message back to browser.