💫 This program allows you to do requests in Rust without reqwest !

Related tags

Command-line Zapros
Overview

Zapros

💫 This program allows you to do requests in Rust without reqwest !

Usage :

Get

use crate::http_client::HttpClient;
use crate::http_client::HttpMethod::Get;

match HttpClient::request(Get, url, None) {
    Ok(Some(http_response)) => {
        println!("Response status code: {}", http_response.status_code);
        println!("Response status text: {}", http_response.status_text);
        println!("Response JSON body:\n{}", http_response.json_body);
        println!("Duration: {:?}", http_response.duration);
        println!("Headers:");
        for (name, value) in http_response.headers {
            println!("{}: {}", name, value);
        }
    }
    Ok(None) => {
        eprintln!("Invalid URL");
        std::process::exit(1);
    }
    Err(err) => {
        eprintln!("Request failed: {:?}", err);
        std::process::exit(1);
    }
}

Delete

use crate::http_client::HttpClient;
use crate::http_client::HttpMethod::Delete;

match HttpClient::request(Delete, url, None) {
    Ok(Some(http_response)) => {
        if http_response.status_code == 200 {
            println!("Delete successful (Status: 200 OK)");
        } else if http_response.status_code == 204 {
            println!("Delete successful (Status: 204 No Content)");
        } else {
            println!("Unexpected response: {} {}", http_response.status_code, http_response.status_text);
        }
    }
    Ok(None) => {
        eprintln!("Connection timeout or invalid URL");
        std::process::exit(1);
    }
    Err(err) => {
        eprintln!("Request failed: {:?}", err);
        std::process::exit(1);
    }
}

Post

use crate::http_client::HttpClient;
use crate::http_client::HttpMethod::Post;

match HttpClient::request(Post, post_url, Some(&json_data)) {
    Ok(Some(http_response)) => {
        if http_response.status_code == 201 {
            println!("Post successful (Status: 201 Created)");
            println!("Response JSON body:\n{}", http_response.json_body);
        } else {
            println!("Unexpected response: {} {}", http_response.status_code, http_response.status_text);
        }
    }
    Ok(None) => {
        println!("Request was successful, but no response received");
    }
    Err(err) => {
        eprintln!("Request failed: {:?}", err);
        std::process::exit(1);
    }
}

Returns

pub struct HttpResponse {
    pub status_code: u16,
    pub status_text: String,
    pub json_body: String,
    pub duration: Duration,
    pub headers: HashMap<String, String>,
}
You might also like...
FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.
FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.

Connect quickly to your services 🚀 FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config. Instal

Jumpy is a tool that allows to quickly jump to one of the directory you've visited in the past

Jumpy Jumpy is a tool that allows to quickly jump to one of the directory you've visited in the past. It is heavily inspired by Zoxide but is more lig

This is a simple command-line interface tool that allows you to interact with ChatGPT from OpenAI or Azure.

HeyGPT This is a simple command-line interface tool that allows you to interact with ChatGPT from OpenAI or Azure. You can use it to: Chat with ChatGP

tmplt is a command-line interface tool that allows you to quickly and easily set up project templates for various programming languages and frameworks
tmplt is a command-line interface tool that allows you to quickly and easily set up project templates for various programming languages and frameworks

tmplt A User Friendly CLI Tool For Creating New Projects With Templates About tmplt is a command-line tool that lets users quickly create new projects

bevy_scriptum is a a plugin for Bevy that allows you to write some of your game logic in a scripting language

bevy_scriptum is a a plugin for Bevy that allows you to write some of your game logic in a scripting language. Currently, only Rhai is supported, but more languages may be added in the future.

A filesystem driver that allows you to view your Blackboard course contents as if they were normal files and folders on your system!
A filesystem driver that allows you to view your Blackboard course contents as if they were normal files and folders on your system!

BlackboardFS Blackboard: noun A website so bad that it might as well be a network drive. BlackboardFS is a filesystem driver that allows you to view y

A crate that allows you to mostly-safely cast one type into another type.

A crate that allows you to mostly-safely cast one type into another type. This is mostly useful for generic functions, e.g. pub fn fooS(s: S) {

A tool that allows you to modify, edit, and recompile the AST script of Artemis engine.

Artemis AST Script Processor This utility offers a set of Rust functions to parse and manipulate Artemis AST-based scripts. Features Tokenization: Con

A crate to help you copy things into raw buffers without invoking spooky action at a distance (undefined behavior).

🗜 presser Utilities to help make copying data around into raw, possibly-uninitialized buffers easier and safer. presser can help you when copying dat

Owner
zqo
Developer ⚛️
zqo
CLI program for sending one-off requests to the VTube Studio API

vtubestudio-cli (vts) CLI program for sending one-off requests to the VTube Studio API. It connects to the websocket, authenticates, performs one or t

null 2 Nov 24, 2021
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.

?? This program is designed to translate text into the correct layout when typing is incorrect. ?? Example ghbdtn -> привет Just (by default) pressing

Gest Se 5 Jan 26, 2023
A super simple /sbin/init for Linux which allows running one and only one program

Summary High-performance /sbin/init program for Linux This is designed to do literally nothing but accept binaries over the network and run them as a

null 19 Dec 4, 2023
This is an example Nostr rust project to enable '402 Payment Required' responses for requests to paid content.

Nostr Paywall Example This is an example Nostr rust project to enable 402 Payment Required responses for requests to paid content. To prove payment, a

Blake Jakopovic 6 May 6, 2023
A simple program that provides DBus interface to control display temperature and brightness under wayland without flickering

wl-gammarelay-rs Like wl-gammarelay, but written in rust, runs on a single thread, has three times less SLOC and uses DBus (for simplicity). Dbus inte

Max Verevkin 33 Nov 23, 2022
Use asynchronous api requests in conjunction with yew's suspense feature

Yew API Hook Use asynchronous api requests in conjunction with yew's suspense feature Usage #[function_component] fn App() -> Html { html! {

Mara Schulke 3 Jan 15, 2023
Components of Fornjot that are no longer actively maintained. Pull requests still welcome!

Fornjot - Extra Components About These are extra components from the Fornjot repository, that are no longer actively maintained. Fornjot's goal was to

Hanno Braun 4 Jun 6, 2023
Rust crate that allows you to display status & progress information in a terminal

status-line This crate allows you to display status & progress information in a terminal This crate handles the problem of displaying a small amount o

Piotr Kołaczkowski 20 Dec 27, 2022
A rust library that allows you to host the CLR and execute dotnet binaries.

ClrOxide ClrOxide is a rust library that allows you to host the CLR and dynamically execute dotnet binaries. I wanted to call it Kepler for no particu

YK 94 Apr 12, 2023
A simple program for C program IO testing. Written in Rust

A simple program for C program IO testing. Written in Rust, using concurrency to speed up valgrind testing. Make sure to update settings at your first run of the program!

null 1 Feb 22, 2022