BagbutikService
public actor BagbutikService
Service for performing requests. A valid JWT is required to perform requests.
It is possible to just perform a single request, or to perform requests until all items has been fetched, if the response type supports paging.
If the JWT has expired, it will be renewed before the request is performed.
-
Initialize a new service for performing requests.
Declaration
Parameters
jwtThe JWT to use as authorization for the requests.
fetchDataThe function to fetch the data for the requests. Defaults to using
URLSession.shared. -
request(_:Asynchronous) Perform a single request.
Declaration
Swift
public func request<T>(_ request: Request<T, ErrorResponse>) async throws -> T where T: Decodable & SendableParameters
requestA
Requestwith the desiredParameters.Return Value
The response of the request, decoded to the
ResponseType. -
request(_:Asynchronous) Undocumented
Declaration
Swift
@discardableResult public func request(_ request: Request<EmptyResponse, ErrorResponse>) async throws -> EmptyResponse -
requestAllPages(_:Asynchronous) Perform all requests required to get all items.
The items for all responses will be in a single array.
Declaration
Swift
public func requestAllPages<T>(_ request: Request<T, ErrorResponse>) async throws -> (responses: [T], data: [T.Data]) where T: Decodable & PagedResponse & Sendable, T.Data: SendableParameters
requestA
Requestwith the desiredParameters.Return Value
The responses of the requests, decoded to the
ResponseTypeand an array with all the items. -
requestNextPage(for:Asynchronous) Perform a single request to get the items for the next page.
Declaration
Swift
public func requestNextPage<T>(for response: T) async throws -> T? where T: Decodable & PagedResponse & SendableParameters
responseThe response for the previous page.
Return Value
The response for the next page, decoded to the
ResponseType. -
requestAllPages(for:Asynchronous) Perform all requests required to get all items for the rest of the pages.
The items for all responses will be in a single array.
Declaration
Swift
public func requestAllPages<T>(for response: T) async throws -> (responses: [T], data: [T.Data]) where T: Decodable & PagedResponse & Sendable, T.Data: SendableParameters
responseThe response for the previous page.
Return Value
The responses for the rest of the pages, decoded to the
ResponseTypeand an array with all the items.
View on GitHub