AsyncHTTPNetworkService is a Swift native library network layer for using Concurrency (Async/Await).
The goal is to provide a simple network library so you don't have to think about it.
let networkService = AsyncHTTPNetworkService() // see below on URLRequestBuilder + URLRequest extension for a easy example creating URL Requests let urlRequest = URLRequest(...) let person: Person = try await networkService.requestObject(urlRequest) // person inherits from Codable let searchResults: [Results] = try await networkService.requestObjects(urlRequest) // networkService.requestVoid // networkService.requestString
AsyncHTTPNetworkService is compatible to iOS 13+. If there are issues surrounding Aync/Await for < iOS 15, please let us know.
URLRequest helpers for ease of creating requests and modifying requests
let baseURL = URLRequestBuilder(baseURL: URL(string: "someendpoint")) baseURL.get("user").queryItems(["tag": "check"]) baseURL.post("login").token("accessToken") baseURL.post("withBody").body(json: codableObject)
AsyncNetworkService provides a basic protocol called
NetworkRequestModifier that allows you to modify the network request before it sends.
2 options are included in AsyncNetworkService
Use this to pass up an
api_key parameter inside a queryItem for all requests. A good example is when you're using a service that requires an api key.
This modifier could easily be updated to add an
api_key to the request headers instead
For each request, this will add in the passed in
authenticationToken inside the
Included in this repo is a SwiftUI example app using AsyncHTTPNetworkService connecting to a Giphy api. Included is showing how using Codable to decode to objects easily.
The network calls to connect to Giphy is layed out in AsyncService.swift
GiphyService class is a list of Routes that are connected, and a function for each endpoint that is connected.
The init of the
GiphyService includes an
APIKeyRequestModifier that adds the a
api_key to the header on each network request.
Made with ❤️ by Robots & Pencils
|Last commit: 2 weeks ago|