AnyRequest
public struct AnyRequest : Request
This struct can be used to construct requests easily without having to define a custom entity
conforming to the Request protocol and defining some HttpService. In a larger application,
you should refrain from using this struct, however, it might be useful in small projects and
when writing tests.
This request fixes the result type to Data such that the user can decode to the desired type
via calling the decode(type:decoder:) function on the returned Response publisher when
scheduling the request.
As this request struct abstracts away the HttpService in favor for a simpler interface,
scheduling can be performed even easier.
Note that this entity does not allow to make insecure requests over HTTP (only HTTPS).
-
Declaration
Swift
public typealias Result = Data
-
Declaration
Swift
public let routes: HttpRoute -
Declaration
Swift
public let method: HttpMethod -
Declaration
Swift
public let query: HttpQuery -
Declaration
Swift
public let header: HttpHeader -
Declaration
Swift
public let body: HttpBody -
Declaration
Swift
public let acceptedStatusCodes: CountableClosedRange<Int> -
Declaration
Swift
public let priority: RequestPriority
-
Initializes a new request for a particular URL.
Declaration
Swift
public init(_ method: HttpMethod = .get, url: UrlConvertible, query: HttpQuery = [:], header: HttpHeader = [:], body: HttpBody = HttpData.Empty(), acceptedStatusCodes: CountableClosedRange<Int> = 200...299, priority: RequestPriority = .default)Parameters
methodThe HTTP method for the request. Defaults to GET.
urlThe URL of the request.
queryThe request’s query parameters. Defaults to no parameters.
headerThe request’s headers. Defaults to no header fields.
bodyThe request’s body. Defaults to an empty body.
acceptedStatusCodesAcceptable status codes for a successful response. Defaults to all 2xx status codes.
priorityThe priority of the request. Defaults to
.default. -
Initializes a new request based on a predefined
HttpService.Declaration
Swift
public init(_ method: HttpMethod = .get, routes: HttpRoute, query: HttpQuery = [:], header: HttpHeader = [:], body: HttpBody = HttpData.Empty(), acceptedStatusCodes: CountableClosedRange<Int> = 200...299, priority: RequestPriority = .default, service: HttpService)Parameters
methodThe HTTP method for the request. Defaults to GET.
routesThe routing paths for the request. The final URL is constructed by making use of the given
service.queryThe request’s query parameters. Defaults to no parameters.
headerThe request’s headers. Defaults to no header fields.
bodyThe request’s body. Defaults to an empty body.
acceptedStatusCodesAcceptable status codes for a successful response. Defaults to all 2xx status codes.
priorityThe priority of the request. Defaults to
.default.serviceThe service representing an API.
-
Schedules the request and, as expected, returns a
Responsepublisher. As the service is transparently constructed when initializing the request, there is no need to pass a service in this case. This implies that the user should not use theschedule(with:)method.Declaration
Swift
public func schedule() -> Response<`Self`>
View on GitHub
AnyRequest Structure Reference