Code Monkey home page Code Monkey logo

requestbuilder's Introduction

RequestBuilder

Originally inspired by http://khanlou.com/2017/01/request-behaviors/
Depends on Soroush Khanlou’s lovely little Promise library, see https://github.com/khanlou/Promise

Setup

This project uses swift package manager. You can generate an Xcode project on the command line by running

swift package generate-xcodeproj 

Usage example

This simple example sends a GET request to https://github.com/foo?foo=bar with Accept and Content-Type headers for JSON, parses the response into a MyObject class, and lets you deal with the object or potential errors in a chainable fashion.

let client = NetworkClient(baseURL: URL(string: "https://github.com")!, defaultRequestBehavior: JSONRequestBehavior())

client.GET("/foo")
  .withQuery(["foo" : "bar"])
  .sendRequest()
  .then({ result in
      return try JSONDecoder().decode(MyObject.self, from: result.data)
  }).then({ object in
    // do something with object
  }).catch { error in
      print("error: \(error)")
  }

requestbuilder's People

Contributors

soryu avatar

Watchers

 avatar  avatar

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.