Connect with us

Code

Papyrus – A type-safe HTTP client for Swift

Papyrus is a type-safe HTTP client for Swift.

It turns your APIs into clean and concise Swift protocols.

@API
protocol GitHub {
    @GET("/users/:username/repos")
    func getRepositories(username: String) async throws -> [Repository]
}
let provider = Provider(baseURL: "https://api.github.com/")
let github: GitHub = GitHubAPI(provider: provider)
let repos = try await github.getRepositories(username: "alchemy-swift")

Each function on your protocol represents an endpoint on your API.

Annotations on the protocol, functions, and parameters help construct requests and decode responses.

@API
@Authorization(.bearer("<my-auth-token>"))
protocol Users {
    @GET("/user")
    func getUser() async throws -> User

    @URLForm
    @POST("/user")
    func createUser(email: String, password: String) async throws -> User
}

Features

  •  Turn REST APIs into Swift protocols
  •  Generate Swift Concurrency or completion handler based APIs
  •  JSON, URLForm and Multipart encoding
  •  Easy to configure key mapping
  •  Sensible parameter defaults so you can write less code
  •  Automatically decode responses with Codable
  •  Custom Interceptors & Builders
  •  Generate mock APIs for testing
  •  iOS / macOS support powered by Alamofire
  •  Swift on Server support powered by async-http-client
Papyrus on GitHub: https://github.com/joshuawright11/papyrus
Platform: iOS
⭐️: 117
Advertisement

Trending