Giter VIP home page Giter VIP logo

leannetworking's Introduction

LeanNetworking

The goal

LeanNetworking (LN) is a thin wrapper on URLSession APIs that is built to provide ergonomic Networking functionality for iOS Applications.

Features

  • Ergonomic
  • Combine compatible
  • Declarative syntax
  • Light and fast
  • Decoding/Encoding with Codable
  • Multilevel logging

The goal

The goal of the package is to provide clear, concise and ergonomic API for work with server side services.

Usage

Add LeanNetworking SPM package:

dependencies: [
    .package(name: "LeanNetworking", url: "[email protected]:onofftelecom/albums-ios-lean-networking.git", .branch("master"))
]

Import where appropriate:

import LeanNetworking

POST request

Let's say you need to send JSON encodable SomeStruct in a POST request and receive JSON that decodes into SomeResponse struct.

You can use either Promise or a Callback to receive values:

let payload = SomeStruct(
    field1: "field_1_value",
    field2: 2
)

// In case you want to use promises        
Endpoint<SomeResponse>(baseURL: "YOUR_URL")
            .post("the/part/of/the/url", body: payload, token: "YOUR_AUTH_BEARER_IF_NEEDED")
            .asFuture()
            
// In case you want to use Callback        
Endpoint<SomeResponse>(baseURL: "YOUR_URL")
            .post("the/part/of/the/url", body: payload, token: "YOUR_AUTH_BEARER_IF_NEEDED")
            .call { someResponse in /* Your callback implementation */ }

GET, POST, PUT...

Performed in similar fashion as POST requests with the exception that parameters are handled in a way as follows:

Endpoint<SomeRespoinse>(baseURL: "YOUR_URL")
            .get(
                "some/url/part",
                optionalParameters: [
                    Endpoint.OptionalPair(key: "someParam", value: "someVal"),
                    Endpoint.OptionalPair(key: "limit", value: 0),
                    Endpoint.OptionalPair(key: "offset", value: 10)
                ],
                token: "YOUR_AUTH_BEARER_IF_NEEDED"
            )
            .asFuture()

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.