RequestProviding
public protocol RequestProviding
A type that provides an interface to create requests to an API.
Overview
For each API, create a type that conforms to RequestProviding and implement the base URL of the API. Using this
type you can create Requests for the different endpoints of the API using the construction methods provided by the
protocol.
You can optionally implement the request(to:using:) method to customize the default request provided by the other
construction methods.
See also
AnonymousRequestProvider
-
The base url of all requests to the API. Convention dictates that this URL should not have a trailing slash.
Declaration
Swift
var baseURL: URL { get } -
request(to:using:)Default implementationConstructs a new request to an endpoint of the API using a specific HTTP method.
Default Implementation
Declaration
Swift
func request(to endpoint: String, using method: HTTPMethod) -> Request<Self, Void>Parameters
endpointThe endpoint for the request.
methodThe HTTP method for the request.
Return Value
A new
Requestto the endpoint using the method.
-
get(_:from:)Extension methodConstructs a
GETrequest for a resource at an endpoint of the API.Declaration
Swift
public func get<NewResource>(_ resourceDecoder: ResponseDecoder<NewResource>, from endpoint: String) -> Request<Self, NewResource>Parameters
resourceDecoderA decoder for the resource at the endpoint.
endpointThe endpoint to retrieve the resource from.
Return Value
A new request for the resource at the endpoint
-
post(_:to:)Extension methodConstructs a
POSTrequest sending a body of data to an endpoint of the API.Declaration
Swift
public func post(_ body: BodyProvider, to endpoint: String) -> Request<Self, Void>Parameters
bodyThe data to send in the request’s body.
endpointThe endpoint to send the data to.
Return Value
A new request to send the data to the endpoint.
-
put(_:to:)Extension methodConstructs a
PUTrequest sending a body of data to an endpoint of the API.Declaration
Swift
public func put(_ body: BodyProvider, to endpoint: String) -> Request<Self, Void>Parameters
bodyThe data to send in the request’s body.
endpointThe endpoint to send the data to.
Return Value
A new request to send the data to the endpoint.
-
patch(_:with:)Extension methodConstructs a
PATCHrequest sending a body of data to an endpoint of the API.Declaration
Swift
public func patch(_ endpoint: String, with body: BodyProvider) -> Request<Self, Void>Parameters
endpointThe endpoint to send the data to.
bodyThe data to send in the request’s body.
Return Value
A new request to send the data to the endpoint.
-
delete(_:)Extension methodConstructs a
DELETErequest for a resource at an endpoint of the API.Declaration
Swift
public func delete(_ endpoint: String) -> Request<Self, Void>Parameters
endpointThe endpoint of the resource to delete.
Return Value
A new request to delete a resource.
-
head(_:)Extension methodConstructs a
HEADrequest for the headers of a resource at an endpoint of the API.Declaration
Swift
public func head(_ endpoint: String) -> Request<Self, Void>Parameters
endpointThe endpoint of the resource to retrieve the headers of.
Return Value
A new request to retrieve the headers of a resource.
View on GitHub
RequestProviding Protocol Reference