No description
Find a file
2024-03-04 12:05:42 +01:00
examples moved get binary to examples 2024-03-01 13:23:09 +01:00
src added convenience functions get and post 2024-03-04 12:05:42 +01:00
.gitignore initial commit 2024-02-27 23:50:36 +01:00
Cargo.lock (slow) dns resolution 2024-02-29 22:01:30 +01:00
Cargo.toml (slow) dns resolution 2024-02-29 22:01:30 +01:00
LICENSE.txt initial commit 2024-02-27 23:50:36 +01:00
README.md added examples in readme 2024-03-01 13:22:58 +01:00

Request

A library for making HTTP requests.

Examples

A simple GET request:

use request::Request;

// ... start a local server on port 8000 ...
let request = Request::get("localhost:8000");
let response = request.send().unwrap();
assert_eq!(response.status, 200);

Adding headers:

use request::Request;

// ... start a local server on port 8000 ...
let response = Request::get("localhost:8000")
    .header("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==")
    .send()
    .unwrap();
assert_eq!(response.status, 200);

A POST request with serialized JSON data.

use request::Request;

#[derive(miniserde::Serialize)]
struct Example { code: u32, message: String }

let data = Example { code: 123, message: "hello".to_string() };
let json = miniserde::json::to_string(&data);
let request = Request::post("example.org/api", &json);
assert_eq!(
    format!("{request}"),
    "POST /api HTTP/1.1\r\nHost: example.org\r\n\r\n{\"code\":123,\"message\":\"hello\"}"
);