Skip to content

Simple & Clean and Swift Networking

License

Notifications You must be signed in to change notification settings

Mercen-Lee/Sora

Repository files navigation

Sora

Swift Platforms Swift Package Manager License

Elegant Networking in Swift. But more Swift.

Sora is an declarative Alamofire wrapper.

Requirements

Platform Minimum Swift Version Installation
iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ 5.5 Swift Package Manager

Installation

Swift Package Manager

  • File -> Add Packages... And paste the repository URL.
  • Or add it to the dependencies value of your Package.swift.
dependencies: [
  .package(url: "https://github.com/Mercen-Lee/Sora.git", .branch("main"))
]

Usage

Service

struct Sample: Service {

    let endpoint: URL = .init(string: "https://sample.com/api/")!
    let interceptor: Interceptor = .init()
    let path: [String]
}

GET Request

struct GetUserRequest: Requestable {

    let route = Sample.path("user")
    let method: RequestMethod = .get
}

AF.request(GetUserRequest())

POST Request

struct PostUserRequest: Requestable, Body {

    let route = Sample.path("user", "post")
    let method: RequestMethod = .post
    
    let body: Body
    
    struct Body: Encodable {
        let id: Int
        let name: String
    }
}

AF.request(PostUserRequest(body: .init(id: 1, name: "mercen")))

Simple Concurrency

do {
    let response = try await GetUserRequest()
        .request(with: AnyDecodable.self)
} catch let error {
    // on Error
}