vapor-docs/3.0/docs/http/request.md

1.2 KiB

Request

When a client connects with an HTTP Server it sends a Request. This HTTP request will be processed as discussed here and resolved into a Response. This is the response in the http Request/Response model.

Requests consist of a Method, URI and Headers.

Requests can optionally also contain a Body.

Requests are Extensible.

Accessing Request information

Creating a Request

Creating requests is necessary for HTTP Clients.

A request accepts a method, uri, version, headers and body. The version's default is recommended. The body is optional.

The body can be a Body or BodyRepresentable. If the body is a BodyRepresentable the Response initializer will become throwing.

let request1 = Request(
                method: .get,
                uri: uri,
                headers: headers,
                body: body
              )

let request2 = try Request(
                method: .get,
                uri: uri,
                headers: headers,
                body: bodyRepresentable
              )