GithubHelp home page GithubHelp logo

afterxleep / wirekit Goto Github PK

View Code? Open in Web Editor NEW
28.0 2.0 7.0 87 KB

A simple Swift Networking library for consuming REST API's

License: MIT License

Swift 100.00%
swift networking library ios macos tvos watchos

wirekit's Introduction

WireKit

Swift

A simple networking library using modern async/await and URLSession.

WireKit is designed to facilitate consumption of RestFul APIs and takes care of fetching and decoding JSON data, gracefully handling errors so you can focus on what's important in your app.

Features

  • Super simple configuration
  • Simple REST API consumption
  • Automatic JSON encoding/decoding via Codable
  • Combine backed async requests
  • Easy error handling

Requirements

  • iOS 15+ / macOS 10.15+ / tvOS 13.0+ / watchOS 5.0+
  • Xcode 14+
  • Swift 5.5+

Installation

Swift Package Manager

The fastest way to install is via SPM. Just add a new package using this repo URL and point it to the current Major Version

Versioning and support for other package managers (Cocoapods & Carthage) coming soon.

Sample App

The Example application is a simple Todo List app that leverages Wirekit to easily fetch and manage items.

Usage

Check out the Quick Start guide

WKRequest

Futher documentation for advanced use of WKRequest is also available.

wirekit's People

Contributors

afterxleep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wirekit's Issues

Decode body of errors

Some servers return a body message on errors(>299).

        return urlSession
            .dataTaskPublisher(for: request)
            .tryMap({ data, response in
                if let response = response as? HTTPURLResponse,
                 !(200...299).contains(response.statusCode) {
                    throw httpError(response.statusCode)
                }
                return data
            })
            .decode(type: ReturnType.self, decoder: decoder)
            .mapError { error in
               handleError(error)
            }
            .eraseToAnyPublisher()

The above code chunk in dispatch() only returns data on codes between 200...299.

It would be great if the library would return both data and error with errors >299.

Option to change JSON decoding strategies

If the server responds with snake_case_fields, it would be a great feature to allow WireKit to apply the .convertFromSnakeCase key decoding strategy(and also the date decoding strategy):

            let decoder: JSONDecoder = JSONDecoder()
            decoder.keyDecodingStrategy = .convertFromSnakeCase
            decoder.dateDecodingStrategy = .iso8601

Refresh token

I am trying to add refresh token。
But I failed.
Any thoughts or suggestions are greatly appreciated. ^_^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.