fwetch

Crates.iofwetch
lib.rsfwetch
version0.1.2
sourcesrc
created_at2022-08-31 21:21:29.235742
updated_at2022-08-31 21:29:37.054403
descriptionBrought from NodeJs to rust.
homepage
repositoryhttps://github.com/franklinblanco/fwetch
max_upload_size
id655922
size11,153
Franklin Blanco (franklinblanco)

documentation

https://docs.rs/fwetch/

README

Fwetch

This package

Uses Reqwest by Franklin Blanco

Brought to you from the javascript world, this is a fetch() implementation. But as the name suggests, it utilizes reqwest.

How to use this crate?

Useful features:

Fwetch

// Say you have a struct
#[derive(Serialize, Deserialize)] // <-- This is from serde (serde.rs)
struct Person{
	pub name: String
}
// If this panics you will get more context regarding what happened than you usually would with reqwest.
let person: Person = fwetch("testurl.com", Method::Get, None, None).await.unwrap();
// You can now use this struct freely.

Interopability with Actix-web (Optional feature called "actix"). Enable by adding to your Cargo.toml

[dependencies]
fwetch = { version = "0", features = ["all"] }

This allows you to create a proxy with two lines of code! Convert an actix request into a reqwest with convert_actix_request_to_reqwest() and send it with forward_request()

use actix_web::{HttpRequest, HttpResponse, web};

use serde_json::Value;

use fwetch::helpers::actix::{convert_actix_request_to_reqwest, forward_reqwest};

[post("/some/route")]
async fn route(request: HttpRequest, body: web::Json<Value>) -> HttpResponse {
	let converted_request = convert_actix_request_to_reqwest(&request, &body.0).unwrap();
	forward_reqwest(converted_request).await.unwrap()
}

Known issues with Reqwest

If you get a compilation error that's really long and confusing, it's probably because you don't have openssl (or at least the version reqwest needs). Solution: (Cargo.toml)

[dependencies]
openssl = { version = "0.10", features = ["vendored"] }
Commit count: 7

cargo fmt