Review of HTTP Requests and Responses
The next section has a REST-style sample service whose URL is:
http://localhost:8080/predictions/
If this URL is typed into a browser’s window, the browser generates a request similar to:
GET/predictions/HTTP/1.1User-Agent:Mozilla/5.0(X11;Linuxx86_64)Chrome/24.0.1312.56Host:localhost:8080Accept:text/html
The browser parses the entered URL into these parts, with clarifications below:
GET /predictions/ HTTP/1.1This is the HTTP request start line:
- GET is the HTTP method (verb).
-
/predictions/is the URI (resource’s name). -
HTTP/1.1is the HTTP version that the requester is using.
User-Agent: Mozilla/5.0 (X11; Linux x86_64) Chrome/24.0Immediately after the start line come the HTTP request header elements or headers for short. Each element is a key/value pair with a colon (
:) separating the key on the left from the value on the right. In this element,User-Agentis the key, and everything to the right of the colon is the value. Chrome is the browser used in this request, and Mozilla/5.0 specifies a browser compatibility type. TheUser-Agentinformation also includes the operating system in use, 64-bit Linux. Of interest here is that keyUser-Agentcaptures the intended meaning: it is the application (agent) that a user employs to make a request.Host: localhost:8080In
localhost:8080, the network address of the machine that hosts the resource is to the left of the colon; the port number, in this case8080, is to the right. In this example, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access