GithubHelp home page GithubHelp logo

ureq's Introduction

ureq

Minimal request library in rust.

Usage

// requires feature: `ureq = { version = "*", features = ["json"] }`
#[macro_use]
extern crate ureq;

fn main() {

    // sync post request of some json.
    let resp = ureq::post("https://myapi.acme.com/ingest")
        .set("X-My-Header", "Secret")
        .send_json(json!({
            "name": "martin",
            "rust": true
        }));

    // .ok() tells if response is 200-299.
    if resp.ok() {
        // ...
    }
}

Features

To enable a minimal dependency tree, some features are off by default. You can control them when including ureq as a dependency.

    ureq = { version = "*", features = ["json", "charset"] }
  • tls enables https. This is enabled by default.
  • json enables response.into_json() and request.send_json() serde json.
  • charset enables interpreting the charset part of Content-Type: text/plain; charset=iso-8859-1. Without this, the library defaults to rust's built in utf-8.

Motivation

  • Minimal dependency tree
  • Obvious API
  • Convencience over correctness

This library tries to provide a convenient request library with a minimal dependency tree and an obvious API. It is inspired by libraries like superagent and fetch API.

This library does not try to enforce web standards correctness. It uses HTTP/1.1, but whether the request is perfect HTTP/1.1 compatible is up to the user of the library. For example:

    let resp = ureq::post("https://myapi.acme.com/blah")
        .set("Jättegött", "Vegankörv")
        .call();

The header name and value would be encoded in utf-8 and sent, but that is actually not correct according to spec cause an HTTP header name should be ascii. The absolutely correct way would be to have .set(header, value) return a Result. This library opts for convenience over correctness, so the decision is left to the user.

Sync (for now)

This library uses blocking socket reads and writes, for now. The async story in rust is in heavy development and when used currently pulls in a heavy dependency tree (tokio etc). Once more async support is in rust core and won't drag those dependencies, this library might change.

TODO

  • Forms with application/x-www-form-urlencoded
  • multipart/form-data
  • Expect 100-continue
  • Use rustls when ring with versioned asm symbols is released. (PR is not resolved, but most implementations have settled on 0.13)

License

Copyright (c) 2019 Martin Algesten

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

ureq's People

Contributors

algesten avatar lolgesten avatar fauxfaux avatar orf avatar owez avatar razvanrotari avatar

Watchers

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