cdumay_http_client

Crates.iocdumay_http_client
lib.rscdumay_http_client
version0.3.2
sourcesrc
created_at2024-07-13 09:41:24.349986
updated_at2024-07-13 10:16:34.94773
descriptionA library to call remote web application
homepagehttps://github.com/cdumay/rust-cdumay_http_client
repositoryhttps://github.com/cdumay/rust-cdumay_http_client
max_upload_size
id1302183
size33,952
Cédric Dumay (cdumay)

documentation

https://docs.rs/cdumay_http_client

README

cdumay_http_client License: BSD-3-Clause cdumay_http_client on crates.io cdumay_http_client on docs.rs Source Code Repository

cdumay_http_client is a basic library used to standardize result and serialize them using serde.

Quickstart

Cargo.toml:

[dependencies]
cdumay_error = "0.3"
cdumay_result = "0.3"
cdumay_http_client = "0.3"

main.rs:

extern crate cdumay_error;
extern crate cdumay_http_client;
extern crate serde_json;

use cdumay_error::JsonError;
use cdumay_http_client::authentication::NoAuth;
use cdumay_http_client::{ClientBuilder, HttpClient};

fn main() {
    use cdumay_http_client::BaseClient;
let cli = HttpClient::new("https://www.rust-lang.org").unwrap();
    let result = cli.get("/learn/get-started".into(), None, None, None, None);

    match result {
        Ok(data) => println!("{}", data),
        Err(err) => println!("{}", serde_json::to_string_pretty(&JsonError::from(err)).unwrap()),
    }
}

Output:

<!doctype html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <title>
[...]

Errors

Errors can be displayed using cdumay_error:

{
  "code": 500,
  "message": "error trying to connect",
  "msgid": "Err-05192"
}
Commit count: 0

cargo fmt