Giter Club home page Giter Club logo

curly's Introduction

Curly

This package wraps Perfect-CURL into a Vapor 3 Client. If you are running into issues with URLSession on Linux, or you want cookies or proxy support, this might be the way out.

Usage

1. Add this package as a dependency to your Vapor 3 project

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "VaporApp",
    dependencies: [
        // ๐Ÿ’ง A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
        .package(url: "https://github.com/vzsg/Curly.git", from: "0.4.0"),
        // ... other dependencies ...
    ],
    targets: [
        .target(name: "App", dependencies: ["Vapor", "...", "CurlyClient"]),
        // ... other targets ...
    ]
)

2. Register the CurlyProvider

// Typically, this is part of configure.swift
import Vapor
import CurlyClient
// ... other imports ...


public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
    try services.register(CurlyProvider())
    config.prefer(CurlyClient.self, for: Client.self)

    // ... other configuration ...
}

3. Profit!

Your Vapor app now uses curl directly instead of URLSession.

4. Extra profit: CurlyOptions

From 0.3.0, Curly exposes a few useful options from cURL that are otherwise not available via the Client interface, or even URLSession. To use them, you must register Curly via the CurlyProvider as seen in step 2.

With that in place, you can call Request.addCurlyOption in either the beforeSend closure when using the convenience functions of Client, or on the Request instance itself when using Client.send() and a self-built Request object.
See the tests for examples of both methods.

Warning: Calling Request.addCurlyOption without the Provider will result in a fatal error in debug builds, and a warning print in release builds.

Available options

  • proxy(String)

    Equivalent to the -x/--proxy parameter of curl, which enables proxying via a HTTP, HTTPS or SOCKS proxy.

  • proxyAuth(user: String, password: String)

    Equivalent to the -U/--proxy-user parameter of curl, which allows specifying the username and password to use when authenticating to the proxy server.

  • timeout(seconds: Int)

    Equivalent to the -m/--max-time parameter of curl, which allows specifying the maximum time allowed to service the request.

  • connectTimeout(seconds: Int)

    Equivalent to the --connect-timeout parameter of curl, which allows specifying the maximum time allowed for the connection to the server.

  • cookieJar(String)

    Equivalent to the both the -b/--cookie and -c/--cookie-jar parameters of curl. The file name provided with the option will be used as a cookie storage โ€“ reading and writing โ€“ for this request. See the tests for an example.

  • followRedirects(Bool)

    Equivalent to the -L/--location parameter of curl, which enables following redirects automatically.

  • insecure(Bool)

    Equivalent to the -k/--insecure parameter of curl, which can disable verification of the certificates received from the remote server.

curly's People

Contributors

vzsg avatar tjshae avatar fredericruaudel avatar mxcl avatar

Watchers

James Cloos 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.