Skip to content

CSP (coroutine) based Swift HTTP+HTTPS client for macOS and Linux

License

Notifications You must be signed in to change notification settings

ZewoGraveyard/HTTPClient

Repository files navigation

HTTPClient

Swift License Slack Travis Codecov Codebeat

Installation

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/Zewo/HTTPClient.git", majorVersion: 0, minor: 14)
    ]
)

Usage

Creating a client

let client = try Client(url: "http://httpbin.org")

Basic GET request

let response = try client.get("/get")

POST request with JSON body

let content: Map = [
    "hello": "world",
    "numbers": [1, 2, 3, 4, 5]
]
let body = try JSONMapSerializer.serialize(content)
let response = try client.post("/post", body: body)

Parsing response body

// converts response to a common type `Map` from pool of types
let contentNegotiation = ContentNegotiationMiddleware(mediaTypes: [.json, .urlEncodedForm], mode: .client)
let response = try client.get("/get", middleware: [contentNegotiation])
print(response.content)

Support

If you need any help you can join our Slack and go to the #help channel. Or you can create a Github issue in our main repository. When stating your issue be sure to add enough details, specify what module is causing the problem and reproduction steps.

Community

Slack

The entire Zewo code base is licensed under MIT. By contributing to Zewo you are contributing to an open and engaged community of brilliant Swift programmers. Join us on Slack to get to know us!

License

This project is released under the MIT license. See LICENSE for details.