Coder Social home page Coder Social logo

phsym / http-rs Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 1.2 MB

It's just a pet project I made to discover and learn Rust. You should not use it, and use hyper (https://hyper.rs) instead

Home Page: http://phsym.github.io/http-rs/

License: BSD 3-Clause "New" or "Revised" License

Rust 100.00%

http-rs's Introduction

License Build Status

http-rs

Documentation

Copyright © 2015 Pierre-Henri Symoneaux

THIS SOFTWARE IS DISTRIBUTED WITHOUT ANY WARRANTY
Check LICENSE.txt file for more information.

A simple and low level http/https client toolkit written in Rust. This is just a pet project I used to discover and learn Rust. I advise you to have a look at Hyper instead. Please consider that no design is stable for now here. I'm just a rust noob who still have a lot to learn on this beautifull new language.

How to build

The library has an optional "ssl" feature that enable HTTPS over SSL. SSL support is enabled by default but can be disabled if not needed. SSL support depends on rust-openssl which requires both the OpenSSL runtime libraries and headers to be built.

Without SSL support

As usual with Cargo project, simply run

cargo build --no-default-features

And to build html documentation, run

cargo doc --no-default-features

With SSL support

Building with SSL support require beeing able to build rust-openssl. Also, gcc will be required. Please have a look on rust-openssl and gcc-rs README files for detailed information about building opennssl. If environment configuration satisfies everything needed to build SSL support, then to build simply run

cargo build

And to build html documentation, run

cargo doc

How to use

More often, you will include the library as a dependency to your project. In order to do this, add the following lines to your Cargo.toml file :

[dependencies.http-rs]
git = "https://github.com/phsym/http-rs.git"
# To disable SSL support, default features need to be disabled by uncommenting the following line
# default-features = false

Then you can start using it the following way :

#[macro_use] extern crate http;
use http::client::*;
use http::methods::Method;

fn main() {
	let mut http = HttpClient::new("www.google.com:80").unwrap();
	match http.send(Method::GET, /, None, None) {
		Ok(reply) => {},// Do something with the reply
		Err(e) => panic!("Cannot send request : {}", e)
	}
	// The same is possible on HTTPS :
	let mut https = HttpsClient::new("www.google.com:443").unwrap();
	// (...)
}

If you want to create an HTTP client hiding which implementation is used (either HttpClient or HttpsClient), you can get a boxed Http trait with the http::open function like this :

#[macro_use] extern crate http;
use http::{Protocol, open};

fn main {
	let mut http = open(Protocol::HTTP, "www.google.com:80").unwrap();
	// Do something with http
	let mut https = open(Protocol::HTTPS, "www.google.com:443").unwrap();
	// Do something with https;
}

Additional examples are provided in documentation and in examples directory

http-rs's People

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.