[][src]Crate nano_get

This crate provides a basic implementation of the HTTP(s) GET Method.

This uses only the standard Rust Library and has no 3rd party dependencies by default.

Quick Example

An example usage is shown below:

let response = nano_get::get_http("http://example.com");
println!("{}", response);

HTTPS

A HTTPS version is provided since v0.2.x that depends on OpenSSL & the Rust OpenSSL wrapper crate. This can be enabled by the "https" feature flag (which is NOT activated by default).

This provides you with the nano_get::get_https method which has the same signature as the standard nano_get::get_http method.

Unified HTTP GET

From version 0.2.x, we profide the new unified nano_get::get method which activates the specific version of http/https GET, based on the protocol of the URL.

However, please note that the https part still depends on the "https" feature flag (which is NOT activated by default). The nano_get::get falls back on the regular http version, incase the "https" feature flag is not enabled.

An example usage of the unified get is shown below:

let response = nano_get::get("http://dummy.restapiexample.com/api/v1/employees");
println!("{}", response);

or, with the "https" feature flag enabled and the OpenSSL library present,

let response = nano_get::get("https://www.google.com");
println!("{}", response);

Executing HTTP(s) Requests:

There are two ways to execute the HTTP(s) requests.

Basic Get

The basic version, demonstrated by the use of the nano_get::get function, which takes a url and returns the body of the response.

Example

let response = nano_get::get("https://www.google.com");
println!("{}", response);

Request-Response based

Another more fine-grained method exists by using the nano_get::Request object. This gives you access to request headers, optional request body and the execution returns a nano_get::Response object. This allows inspection of HTTP Response codes, response body, etc.

Example

use nano_get::Response;
let mut request = nano_get::Request::default_get_request("http://example.com/").unwrap();
let response: Response = request.execute().unwrap();

For details, check the Request and Response structure documentation.

Structs

Request

This is the basic HTTP Request Object.

Response

This is the HTTP Reponse Object.

ResponseStatus

Represents the status of the Response. This includes HTTP Status Code & Reason Phrase as per RFC-2616.

Url

This is used to represent the various parts of a URL.

Enums

StatusCode

Represents the HTTP Status Codes.

Traits

ToUrl

Represents the ability to be made into a URL.

Functions

get

This is a unified function for the HTTP GET method.

get_http

The basic implementation of the HTTP GET method.

Type Definitions

Header

Coveneince wrapper for a tuple of (key: &str, value: &str) that is to be sent as a HTTP header.