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

    Swift

    public init(jwt: JWT, fetchData: @escaping FetchData = URLSession.shared.data(for:delegate:))

    Parameters

    jwt

    The JWT to use as authorization for the requests.

    fetchData

    The 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

    Parameters

    request

    A Request with the desired Parameters.

    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 : PagedResponse, T : Decodable

    Parameters

    request

    A Request with the desired Parameters.

    Return Value

    The responses of the requests, decoded to the ResponseType and 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 : PagedResponse, T : Decodable

    Parameters

    response

    The 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 : PagedResponse, T : Decodable

    Parameters

    response

    The response for the previous page.

    Return Value

    The responses for the rest of the pages, decoded to the ResponseType and an array with all the items.