← Winnitude! Search  ·  Reader Mode (1761 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 47 LINKS

GitHub - XcodesOrg/AsyncHTTPNetworkService: A Network layer for Swift using Concurrency

Repository navigation

AsyncHTTPNetworkService
Public
forked from isabella232/AsyncHTTPNetworkService

About

A Network layer for Swift using Concurrency

Resources

Readme License Activity Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks Report repository
Branches

Tags
Go to Branches page Go to Tags page    

Latest commit

 

History


50 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
.swiftpm/ xcode/ package.xcworkspace .swiftpm/ xcode/ package.xcworkspace    
AsyncNetworkService.xcodeproj AsyncNetworkService.xcodeproj    
AsyncNetworkService AsyncNetworkService    
AsyncNetworkServiceExample AsyncNetworkServiceExample    
AsyncNetworkServiceTests AsyncNetworkServiceTests    
.gitignore .gitignore    
LICENSE LICENSE    
Package.swift Package.swift    
R&PLogo.png R&PLogo.png    
README.md README.md    

Repository files navigation

AsyncHTTPNetworkService

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.

Example use

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

Compatibility

AsyncHTTPNetworkService is compatible to iOS 13+. If there are issues surrounding Aync/Await for < iOS 15, please let us know.

URLRequestBuilder + URLRequest extension

AsyncHTTPNetworkService includes 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)

Request Modifiers

AsyncNetworkService provides a basic protocol called NetworkRequestModifier that allows you to modify the network request before it sends.

2 options are included in AsyncNetworkService

APIKeyRequestModifier

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

BearerTokenRequestModifier

For each request, this will add in the passed in authenticationToken inside the Authorization header.

Example App

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

Inside the 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.

Maintainers

Matt Kiazyk

Contact

Made with ❤️ by Robots & Pencils

Twitter | GitHub

About

A Network layer for Swift using Concurrency

Resources

Readme License Activity Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks Report repository

Releases

Packages

Contributors

Languages