Skip to content


Vapor's client API allows you to make HTTP calls to external resources. It is built on async-http-client and integrates with the content API.


You can get access to the default client via Application or in a route handler via Request.

app.client // Client

app.get("test") { req in
    req.client // Client

The application's client is useful for making HTTP requests during configuration time. If you are making HTTP requests in a route handler, always use the request's client.


To make a GET request, pass the desired URL to the get convenience method.

req.client.get("").map { res in
    // Handle the response.

There are methods for each of the HTTP verbs like get, post, and delete. The client's response is returned as a future and contains the HTTP status, headers, and body.


Vapor's content API is available for handling data in client requests and responses. To encode content or query parameters to the request, use the beforeSend closure."") { req in
    // Encode query string to the request URL.
    try req.query.encode(["q": "test"])

    // Encode JSON to the request body.
    try req.content.encode(["hello": "world"])
}.map { res in
    // Handle the response.

To decode content from the response, use flatMapThrowing on the client's response future.

req.client.get("").flatMapThrowing { res in
    try res.content.decode(MyJSONResponse.self)
}.map { json in
    // Handle the json response.


You can configure the underlying HTTP client via the application.

// Disable automatic redirect following.
app.http.client.configuration.redirectConfiguration = .disallow

Note that you must configure the default client before using it for the first time.