A swift request & response framework for JSON apis.
This package has been designed to work across multiple swift environments by utilizing conditional checks. It has been tested on Apple platforms (macOS, iOS, tvOS, watchOS), as well as Linux (Ubuntu).
SessionPlus offers a default implementation (URLSessionClient) that allows for requesting data from a JSON api. For example:
leturl=URL(string:"https://api.agify.io")!
letclient=BaseURLSessionClient(baseURL: url)letrequest=Get(queryItems:[URLQueryItem(name:"name", value:"bob")])letresponse=tryawait client.request(request)The Client protocol also offers extensions for automatically decoding responses to any Decodable type.
structApiResult:Decodable{letname:Stringletage:Intletcount:Int}letresponse=tryawait client.request(request)asApiResult...letresponse:ApiResult=tryawait client.request(request)SessionPlus is distributed using the Swift Package Manager.
You can add it using Xcode or by listing it as a dependency in your Package.swift manifest:
letpackage= Package(...
dependencies:[.package(url:"https://github.com/richardpiazza/SessionPlus.git",.upToNextMajor(from:"2.0.0")],...
targets:[.target(
name:"MyPackage",
dependencies:[.product(name:"SessionPlus",package:"SessionPlus"),])])Contributions to SessionPlus are welcomed and encouraged! See the Contribution Guide for more information.