Coder Social home page Coder Social logo

monkeygroover / chttp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sagebind/isahc

0.0 2.0 0.0 197 KB

The practical HTTP client that is fun to use.

Home Page: https://docs.rs/chttp

License: MIT License

HCL 0.36% Shell 0.07% Rust 99.57%

chttp's Introduction

cHTTP

The practical HTTP client that is fun to use.

Crates.io Documentation License

cHTTP provides a clean and easy-to-use interface around the venerable libcurl. Here are some of the features that are currently available:

  • HTTP/2 support.
  • Connection pooling and reuse.
  • Sessions and cookie persistence.
  • Response body streaming.
  • Request body uploading from memory or a stream.
  • Tweakable redirect policy.
  • Persistent cookies across requests.
  • TCP socket configuration.
  • Uses the future standard Rust http interface for requests and responses.

Check out the documentation for details on how to use cHTTP.

Why libcurl?

Not everything needs to be re-invented! For typical use cases, libcurl is a fantastic choice for making web requests. It's fast, reliable, well supported, and isn't going away any time soon.

It has a reputation for having an unusual API that is sometimes tricky to use, but hey, that's why this library exists.

Examples

Really simple example that spits out the response body from https://example.org:

let mut response = chttp::get("https://example.org").unwrap();
let body = response.body_mut().text().unwrap();
println!("{}", body);

Configuring a custom client:

use chttp::{http, Client, Options, RedirectPolicy};
use std::time::Duration;

let mut options = Options::default();
options.timeout = Some(Duration::from_secs(60));
options.redirect_policy = RedirectPolicy::Limit(10);
options.preferred_http_version = Some(http::Version::HTTP_2);

let client = Client::builder()
    .max_connections(Some(4))
    .options(options)
    .build();

let mut response = client.get("https://example.org").unwrap();
let body = response.body_mut().text().unwrap();
println!("{}", body);

Installation

Add this to your Cargo.toml file:

[dependencies]
chttp = "0.3"

License

This library is licensed under the MIT license. See the LICENSE file for details.

chttp's People

Contributors

dependabot-support avatar liamdawson avatar monkeygroover avatar sagebind avatar

Watchers

 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.