HTTP request
The message a client sends to a server: a method, a target, a protocol version, headers, a blank line and an optional body.
In more detail
In GET /tasks?limit=2 HTTP/1.1, the method is GET, the target is the path plus query string, and the version comes last. Headers such as Host and Accept follow, one per line. Because the format is plain text in HTTP/1.1 you can type a request by hand and read exactly what was sent.
Examples
req, err := http.NewRequestWithContext(ctx, http.MethodGet, target.URL, nil)Go: http.NewRequestWithContext(ctx, http.MethodGet, target.URL, nil)In GET /health HTTP/1.1, GET is the method and /health the target; a Host header then names the site. In a packet capture these readable lines help separate an HTTP problem from a transport failure. Headers carry metadata such as the formats the client accepts.m=GET t=/health host=example accept=text lists the method, target and two request headers.Related terms
- HTTP response — The message a server sends back: a protocol version, a status code and phrase, headers, a blank line and usually a body.
- HTTP method — The verb at the start of a web request that says what the client wants, such as GET to read or POST to create.
- HTTP header — A named line of metadata in an HTTP message, such as Content-Type: application/json, that describes the body, the caller or how to handle the exchange.
- payload — The actual data a message carries, as opposed to the headers and framing around it.
- http.Client — The Go type that sends HTTP requests and returns responses, managing connections and timeouts for you.
- URL — A web address, such as https://example.com/docs, made of a scheme, a host, an optional port and a path.
- HTTP — The protocol web browsers and web servers use to send requests and responses.
Taught in
- What An API Is, And The Alternatives — Modern API Architecture: REST, GraphQL & gRPC
- Context Cancellation and Timeouts — Concurrent Systems Programming with Go
- Calling APIs with net/http Client — Concurrent Systems Programming with Go
- Serving HTTP with net/http Server — Concurrent Systems Programming with Go
- HTTP Is Text: Requests, Status Codes And Headers — Linux Fundamentals & Systems Administration