Step1: The Client sends a Request¶
Every conversation on the web starts with a request. The request is a text message created by a client (e.g. a browser, an iPhone app, etc) in a special format known as HTTP. The client sends that request to a server, and then waits for the response.Take a look at the first part of the interaction (the request) between a browser and the xkcd web server:
n HTTP-speak, this HTTP request would actually look something like this:
1 2 3 4 | GET / HTTP/1.1
Host: xkcd.com
Accept: text/html
User-Agent: Mozilla/5.0 (Macintosh)
|
The URI (e.g.
/
, /contact
, etc) is the unique address or location
that identifies the resource the client wants. The HTTP method (e.g. GET
)
defines what you want to do with the resource. The HTTP methods are the
verbs of the request and define the few common ways that you can act upon
the resource:resource:
GET | Retrieve the resource from the server |
POST | Create a resource on the serverIn addition to the first line, an HTTP request invariably contains other
lines of information called request headers. The headers can supply a wide
range of information such as the requested Host , the response formats
the client accepts (Accept ) and the application the client is using to
make the request (User-Agent ). Many other headers exist and can be found
on Wikipedia's List of HTTP header fields article. |
PUT | Update the resource on the server |
DELETE | Delete the resource from the server |
1 | DELETE /blog/15 HTTP/1.1
|
There are actually nine HTTP methods defined by the HTTP specification,
but many of them are not widely used or supported. In reality, many modern
browsers don't support the
PUT
and DELETE
methods.
No comments:
Post a Comment