WrapFast Documentation

Get Started

In-App Purchases

Firebase

WishKit

AI Backend

Xcode Project

API Client

Support

API Client

WrapFast includes a native API Client to make HTTP Requests with the Codable protocol easily and without depending on third party libraries.

To use it, you just have to call it by a Singleton: ApiClient.shared.sendRequest

sendRequest<T: Decodable>(endpoint: Endpoint, queryParams: [URLQueryItem]? = nil, body: Data? = nil, pathExtension: String? = nil, responseModel: T.Type, allowRetry: Bool = true) async -> Result<T, RequestError>

This method is designed to send an asynchronous network request to the specified endpoint and return the result. It utilizes Swift's generics and async/await syntax to streamline API requests and their responses.

Parameters:

Returns:

The endpoints are defined in the Endpoints enum, that conforms to the Endpoint Protocol. Define as many endpoints as you need.

Example of use:

let model: MealVisionRequestModel

let result = try await ApiClient.shared.sendRequest(
            endpoint: Endpoints.vision,
            body: JSONEncoder().encode(model),
            responseModel: MealVisionResponse.self
        )

Endpoints

The Endpoint protocol is designed to provide a structured way to define and manage the various endpoints of a network service in the iOS application. It encapsulates all the necessary information required to construct a network request, including the base URL, path, HTTP method, headers, and request body.

Properties

Extension

The protocol includes an extension for the baseURL property, providing a default implementation. This approach simplifies conforming types by allowing them to inherit the base URL directly from Const.Api.baseURL, ensuring consistency across different endpoints and reducing boilerplate code.

In WrapFast, we define the following endpoints:

enum Endpoints {
    case auth
    case vision
    case chatgpt
    case dalle
    case anthropicMessages
}

Switching over the enum cases, we can define what header, body, method, etc… that each endpoint request will use.

Following the provided examples, you can add and define as many endpoints you need. This way you can make requests to the APIs that your app will need in a clean way, using async/await and in native Swift — without depending on third-party libraries.

<aside> 💡 Take a look at Endpoints.swift in the Xcode project to understand how the code is implemented

</aside>

← Previous

Xcode Project

Next →

Support

On this page