async
enabled, wrapper around the official Swift on the Server async-http-client
. You get a high performance, easy to use interface that makes it easy for your app to communicate with other web applications.
Http
alias. You may use the get
, post
, put
, patch
, delete
, etc functions to make requests.
Client.Response
object that contains a variety of methods to help handle the response.
Request
, Client.Response
also conforms to ContentInspector
so you can use subscripts and dynamic typing to access various fields the response.
RequestBuilder
and contains many methods for constructing requests. If you want to include some JSON content on your requests, you should use the .withJSON()
function which takes a dictionary.
Encodable
type, optionally speciying the JSONEncoder
with which to encode.
withQuery()
(for a single key / value pair) or withQueries()
(for multiple query items).
.withForm()
method lets you send data using the application/x-www-form-urlencoded
content type. Like withJSON()
, it takes either a dictionary or an Encodable
type and an optional URLEncodedFormEncoder
.
.withBody()
to send either Foundation.Data
or a swift-nio ByteBuffer
.
multipart/form-data
request, you’ll use the attach()
method. This takes a name, an attachment contents, and an optional filename.
File
or multiple File
resources directly.
withHeader()
method. Multiple headers may be added using withHeaders()
.
withBasicAuth()
.
withToken()
method.
withTimeout()
, after which your request will be terminated and an error will be thrown.
Client.Response
will have it’s body accumulated into a single ByteBuffer
before returning, so that you don’t need to worry about streamed responses. If you would like to explicitly allow a streamed response, you may do so with the withStream()
function.
async-http-client
library. If you’d like finer grain customization over the internal client configuration, you may specify one using withClientConfig()
.
Client
interface includes a stub()
method allowing you to respond to requests with mock responses.
200
for all outgoing requests on a client, you may use the stub()
function.
stub()
method. If a request doesn’t match any of the provided patterns, it will result in a 200
response. *
is treated as a wildcard. The static stub()
function on Client.Response
lets you quickly create stubbed responses.
Client.Request
parameter and must return a Client.Response
.
assertSent()
function in the AlchemyTest
library. It takes an optional count of expected requests, as well as an optional closure for verifying the request contents. When verifying the request, you may use the RequestInspector
interface as well as the hasPath()
, hasHeader()
, hasPath()
, and hasMethod()
sugar functions.
assertNothingSent()
function.