Swiftpack.co - creekpld/SimpleHTTP as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by creekpld.
creekpld/SimpleHTTP 1.0.0
A simple library to make HTTP Requests using URLRequest and Codable Data.
⭐️ 0
🕓 2 years ago
.package(url: "https://github.com/creekpld/SimpleHTTP.git", from: "1.0.0")

This is not the Repo you are looking for! :alien:

New development is taking place in gitlab.com/pdylong/SimpleHTTP :ok_hand:.

GitHub tag

SimpleHTTP

A simple library to make HTTP Requests using URLRequest and Codable Data.

This Swift library is written in swift version 4.0

Features

  • ☑ Uses only Foundations URLRequest
  • ☑ Very simple one line HTTP Requets
  • ☑ Supports Swift's Codable Models
  • ☑ Supports Linux

Installation

Import Source File

You can just drop the Source File SimpleHTTP.swift into your Project.

Swift Package Manager

// swift-tools-version:4.0

import PackageDescription

let package = Package(
    name: "YourApp",
    products: [
        .executable(name: "YourApp", targets: ["YourApp"]),
    ],
    dependencies: [
        .Package(url: "https://github.com/creekpld/SimpleHTTP.git", from: "1.0.0")
    ],
    targets: [
        .target(
            name: "YourApp",
            dependencies: ["SimpleHTTP"],
            path: "Sources"),
    ]
)

Usage

Synchronous Example:

import SimpleHTTP

let result = httpSync("https://example.com").json() as YourResultModel?

Asynchronous Example:

  httpAsync("https://example.com"){
    ( data, result, error) as
    let result = data.json() as YourResultModel?
    // your code
  })

Advanced Usage

        let request = YourRequestModel(msg: "Hello", description: "World", version: "1.2.3")
        
        let result = httpSync("https://example.com/api/v1/", 
                              "POST", 
                              Data(encode: request),
                              ["Content-Type":"application/json",
                               "Authorization":"Bearer UkGaHu8nT4O05XgoEhA50oPbmWxSI0"],
                              timeout: 120
                            )?.json() as YourResultModel?

TODO

  • ☑ Code Comments / Documentation
  • ☑ Advanced Usage Examples
  • ☐ Some Tests
  • ☐ CI

License

SimpleHTTP is available as open source under the terms of the MIT License.

GitHub

link
Stars: 0
Last commit: 2 years ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v1.0.0
3 years ago

Initial Release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics