Contents

level-two/retroswift

This library provides the approach to API contract definition in the Retrofit-like fashion on Swift.

Features

Supported HTTP methods:

  • @Delete
  • @Get
  • @Head
  • @Patch
  • @Post
  • @Put

Supported parameter types:

  • @Header
  • @Path
  • @Query
  • @JsonBody
  • @FormParam
  • @FormFile

By default parameter name is derived from the variable name, but it can be customized:

@Header("X-Account-Id") var accountId: String = ""

Supported response types:

  • any type conforming to Decodable
  • Either<Response: Decodable, ErrorResponse: Decodable>
  • Empty

Either type allows to get either success or error response.

Response mocking. You can easily mock response by assigning directly to the api's endpoint definition:

api.deleteSchedule = { _ in
    .errorResponse(DeleteScheduleErrorResponse(errorMessage: "Schedule not found"))
}

Adding RetroSwift as a Dependency

Xcode

If you're working with a project in Xcode RetroSwift can be easily integrated:

  1. In Xcode, select File > Add Packages...
  2. Or go to the project's settings, select your project from the list, go to the Package Dependencies and click + button
  3. Specify the Repository: https://github.com/level-two/RetroSwift
  4. Go to the Target, on General tab find Frameworks, Libraries and Embedded content section, click '+' and add RetroSwift library as a dependency

Swift Package Manager

To use this library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/level-two/RetroSwift", from: "0.0.1"),

and include it as a dependency for your target:

.target(
    ...
    dependencies: [
        "RetroSwift",
    ],
    ...
),

Finally, add import RetroSwift to your source code.

Package Metadata

Repository: level-two/retroswift

Default branch: main

README: README.md