Skip to content

A generic wrapper around URLSession & URLRequest API

License

Notifications You must be signed in to change notification settings

adam-leitgeb/APIAdapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APIAdapter

A generic wrapper around URLSession & URLRequest API.

Usage

import APIAdapter

struct LoginRequest: Request {
    var path: String = "/login"
    var method: HTTPMethod = .get
    var requestData: RequestData

    init(email: String, password: String) {
        requestData = .jsonBody([
            "email": email,
            "password": password,
        ], query: nil)
    }
}

let request = LoginRequest(email: "adam@email.com", password: "password")
let apiAdapter = APIAdapter(jsonDecoder: .init())

// NOTE: - Response type has to conform to protocol 'Decodable' and is automatically parsed

apiAdapter.request(request, responseType: String.self) { accessToken in 
    // TODO: - Save AccessToken, display Home
}

About

A generic wrapper around URLSession & URLRequest API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages