Latest 0.1.3
License MIT
Platforms ios 8.0
Dependencies RxSwift, SwiftyJSON


  • RxSwift
  • SwiftyJson
  • Codable mark is required for all Entities.
  • Need to set default ApiEndpoint.baseEndpoint before sending requests or init new ApiClient with with defaultInstance(host:)


class TodoItem: Codable{
    var title: String? = nil

let apiClient = ApiClientImp.defaultInstance("")
let request: ApiRequest<TodoItem> = .request(path: "/todos", method: .get)

    .subscribe(onSuccess: { (items: [TodoItem])
        // use result



For request modification before sending and additional response handling.

Builtin Logging interceptor result example:

>>> [GET]

<<< Status code: (200) 👌
<<< Body: Body: [
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false

Example for custom OAuth2 interceptor:

public class AuthInterceptor: Interceptor {

    private let settings: Settings

    public init(_ settings: Settings) {
        self.settings = settings

    public func prepare(request: inout URLRequest) {
        let authHeader = request.allHTTPHeaderFields?["Authorization"]
        if authHeader == nil, let auth = settings.authToken {
            request.addValue("Bearer (auth.token)", forHTTPHeaderField: "Authorization")

    public func handle(response: NetworkResponse) {
        // empty

Custom Http Body converters

Mark Entity for sending with JsonBodyConvertible protocol

struct NoteEntity: JsonBodyConvertible {

    var date: Date
    var text: String
    var warning_level: Int

let note = NoteEntity(date: Date(), text: "note text", warning_level: Int.max)
let request: ApiRequest<JSON> = .request(path: "/todo/add",
                                         method: .post,
                                         body: note)

apiClient.execute(request: request).subscribe()

Show in output

>>> https://jsonplaceholder.typicode.comtodo/add [POST] Parameters: {"date":558022549.47259104,"text":"note text","warning_level":9223372036854775807}

Custom Response Handler

Before returning result to subscriber response is stepping over stack of ResponseHandler’s

File uploading

let imgs = ["",
            .compactMap { URL(string: $0)! }
            .compactMap { try! Data(contentsOf: $0) }

let files = [UploadFile(name: "file 1.jpg", data: imgs[0], mimeType: "jpg"),
                  UploadFile(name: "file 2.jpg", data: imgs[1], mimeType: "jpg")]

let request: ApiRequest<JSON> = .request("/file/add", method: .post, files: files)

apiClient.execute(request: request).subscribe()

Full list of available operations for request

static public func request<ResponseType: Codable>(
            path: String? = nil,
            method: HttpMethod,
            endpoint: ApiEndpoint = ApiEndpoint.baseEndpoint,
            headers: [Header]? = nil,
            formData: FormDataFields? = nil,
            files: [UploadFile]? = nil,
            body: BodyConvertible? = nil,
            query: QueryField...) -> ApiRequest<ResponseType> {


RxNetworkApiClient is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'RxNetworkApiClient'


starmel, [email protected]


RxNetworkApiClient is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "RxNetworkApiClient",
    "version": "0.1.3",
    "summary": "Simple Rx network library.",
    "description": "See description on github.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "starmel": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.3"
    "platforms": {
        "ios": "8.0"
    "swift_version": "4.0",
    "source_files": "RxNetworkApiClient/Classes/**/*",
    "dependencies": {
        "RxSwift": [],
        "SwiftyJSON": []

Pin It on Pinterest

Share This