Swiftpack.co - Package - dduan/Just

Supported Flatform CocoaPods Carthage compatible Build Status

Just is a client-side HTTP library inspired by python-requests - HTTP for Humans.

Features

Just lets you to the following effortlessly:

  • URL queries
  • custom headers
  • form (x-www-form-encoded) / JSON HTTP body
  • redirect control
  • multipart file upload along with form values.
  • basic/digest authentication
  • cookies
  • timeouts
  • synchronous / asynchronous requests
  • upload / download progress tracking for asynchronous requests
  • link headers
  • friendly accessible results

Use

The simplest request with Just looks like this:

//  A simple get request
Just.get("http://httpbin.org/get")

The next example shows how to upload a file along with some data:

//  talk to registration end point
let r = Just.post(
    "http://justiceleauge.org/member/register",
    data: ["username": "barryallen", "password":"ReverseF1ashSucks"],
    files: ["profile_photo": .url(fileURLWithPath:"flash.jpeg", nil)]
)

if r.ok { /* success! */ }

Here's the same example done asynchronously:

//  talk to registration end point
Just.post(
    "http://justiceleauge.org/member/register",
    data: ["username": "barryallen", "password":"ReverseF1ashSucks"],
    files: ["profile_photo": .url(fileURLWithPath:"flash.jpeg", nil)]
) { r in
    if r.ok { /* success! */ }
}

Read Getting Started on the web or in this playground to learn more!

Install

Here are some ways to leverage Just.

Xcode

Add https://github.com/dduan/Just.git the usual way.

Swift Package Manager

Add the following to your dependencies:

.package(url: "https://github.com/dduan/Just.git",  from: "0.8.0")

… and "Just" to your target dependencies.

Carthage

Include the following in your Cartfile:

github "dduan/Just"

Just includes dynamic framework targets for both iOS and OS X.

CocoaPods

The usual way:

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
  pod 'Just'
end

Manual

Drop Just.xcodeproj into your project navigator. Under the General tab of your project settings, use the plus sign to add Just.framework to Linked Framework and Libraries. Make sure to include the correct version for your target's platform.

It's also common to add Just as a git submodule to your projects repository:

cd path/to/your/project
git submodule add https://github.com/dduan/Just.git

Source File

Put Just.swift directly into your project. Alternately, put it in the Sources folder of a playground. (The latter makes a fun way to explore the web.)

Contribute

Pull requests are welcome. Here are some tips for code contributors:

Work in Just.xcworkspace.

The tests for link headers relies on Github APIs, which has a low per-hour limit. To overcome this, you can edit the Xcode build schemes and add environment variables GITHUB_TOKEN. Learn more about personal tokens here.

For Xcode rebels, checkout Makefile.

HTML documentation pages are generated by literate programmin tool docco

License

MIT, see LICENSE.md.

Github

link
Stars: 1310

Dependencies

Releases

0.8.0 - 2019-06-28 05:53:05

The Swift 5 support release.

0.7.1 - 2018-09-27 08:35:43

0.7.1

Fix code-signing issues reported in #112

0.7.0

Swift 4.2 support

0.7.0 - 2018-09-22 05:30:08

Swift 4.2 support.

0.6.0 - 2017-04-08 23:56:36

In this release, Just is update to Swift 3.1.

New Feature

In addition to Strings, the url parameter can now be an URL.

Changes

Minor changes to the APIs were made to follow the Swift API Design Guidelines

  1. URLQuery is renamed to urlQuery.
  2. HTTPMethods are now lowercase.

0.5.7 - 2016-10-29 22:46:46

Add data chunk for downloading progress (https://github.com/JustHTTP/Just/pull/53). Use the chunk property during a download progress to access the data.

Thank you, @divThis!

0.5.6 - 2016-10-23 18:12:39

Fix a bug in unprompted authentication (https://github.com/JustHTTP/Just/pull/52). Thanks @tomreay!

0.5.5 - 2016-10-23 18:08:06

Adjusted order of some arguments for consistency (see https://github.com/JustHTTP/Just/pull/50 for detail).

Thanks @gtchance!

0.5.3 - 2016-09-18 01:15:14

Swift 3 and Swift package manager support.

0.5.2 - 2016-09-17 21:48:07

Swift 3 support.

0.5.1 - 2016-09-13 00:11:21

Swift 3 support.

0.5.0 - 2016-09-11 07:50:04

Swift 3 support!

v0.4.8 - 2016-07-13 07:33:00

  • fixed issue #38, a percent encoding issue in forms and URL query parameters.
  • added support for unprompted basic HTTP authentication (via Auth header)

- 2016-02-23 01:01:03

Fixed a bug in synchronous request + timeouts. Thanks Marco (@massenz)!

- 2016-02-02 21:43:21

Fixed a silly bug regarding PATCH requests.

v0.4.4 - 2015-11-22 22:40:49

Added option to customize credential persistence through JustSessionDefaults (default value is .ForSession):

let defaults = JustSessionDefaults(credentialPersistence: .None)
let just = JustOf<HTTP>(defaults: defaults)
just.post("http://httpbin.org/post", auth: ("B3rry": "A113n")) // credential will not persist at all.

Read the customization section in quick start guide to learn more!

- 2015-11-12 21:28:51

This version made JustSessionDefaults public so that you can create your own Just sessions with one. For example, the following code creates a session that includes an Authorization header for all requests:

let defaults = JustSessionDefaults(headers: ["Authorization": "\(someAuthKey)"])
let just = JustOf<HTTP>(defaults: defaults)
just.post("http://httpbin.org/post") // this request will contain the Authorization header

v0.4.2 - 2015-10-23 22:32:21

This build contains some project housekeeping.

Probably more interesting notes from v0.4:

  1. HTTPResult now retains reference to its NSURLSessionTask.
  2. as a consequence, you can call HTTPResult.cancel(), which just forwards to HTTPResult.task?.cancel()
  3. The type of json argument got relaxed to AnyObject, so that arrays can be passed in.
  4. Added tvOS target.

v0.4.1 - 2015-10-23 18:05:52

This build contains some project housekeeping.

Probably more interesting notes from v0.4:

  1. HTTPResult now retains reference to its NSURLSessionTask.
  2. as a consequence, you can call HTTPResult.cancel(), which just forwards to HTTPResult.task?.cancel()
  3. The type of json argument got relaxed to AnyObject, so that arrays can be passed in.
  4. Added tvOS target.

v0.4 - 2015-10-23 05:31:19

  1. HTTPResult now retains reference to its NSURLSessionTask.
  2. as a consequence, you can call HTTPResult.cancel(), which just forwards to HTTPResult.task?.cancel()
  3. The type of json argument got relaxed to AnyObject, so that arrays can be passed in.
  4. Added tvOS target.

- 2015-09-02 08:24:37

Just now supports Link Headers. It also gained an adaptor structure internally.

- 2015-08-25 03:42:25

v0.2.2 - 2015-07-26 00:43:41

v0.1.3 - 2015-07-26 00:12:00