An experimental project for rust version of Hertz written by GPT4.

Related tags

Command-line ryze
Overview

Ryze: An experimental Rust Web Framework

Ryze is a minimal web framework for Rust inspired by Hertz and written by GPT4.

Example

Here is a simple example of using the Ryze framework:

use std::net::SocketAddr;
use std::sync::Arc;

use hyper::Body;

use hertz::{Hertz, RequestContext};

mod hertz;

// Index handler
fn index(ctx: &mut RequestContext) {
    let query = ctx.req.uri().query().unwrap_or("");
    let body = query.chars().map(|b| b.to_ascii_uppercase()).collect::<String>();
    *ctx.resp.body_mut() = Body::from(body);
}

// Hello (or ping) handler
fn hello(ctx: &mut RequestContext) {
    *ctx.resp.body_mut() = Body::from("Pong!");
}

#[tokio::main]
async fn main() -> hyper::Result<()> {
    let mut h = Hertz::new();

    // middleware 0
    h.use_fn(Arc::new(|req_ctx| {
        println!("pre-handle 0");
        req_ctx.next();
        println!("post-handle 0");
    }));

    // middleware 1
    h.use_fn(Arc::new(|req_ctx| {
        println!("pre-handle 1");
        req_ctx.next();
        println!("post-handle 1");
    }));

    // route registry
    h.get("/query", Arc::new(index)).await;
    h.get("/ping", Arc::new(hello)).await;

    // run forever
    h.spin(SocketAddr::from(([127, 0, 0, 1], 8000))).await
}
You might also like...
A version control system implemented from scratch in Rust.

Version Control An experiment to write a version control system from scratch in Rust. CLI Usage Usage: revtool COMMAND Commands: init initia

Rust parser/validator for Debian version strings

debian version handling in rust This simple crate provides a struct for parsing, validating, manipulating and comparing Debian version strings. It aim

A better rust version of pokeget.

pokeget-rs A better rust version of pokeget. Usage pokeget pokemon for more info, run pokeget --help Also, if you're using pokeget in your bashrc, t

Truly universal encoding detector in pure Rust - port of Python version

Charset Normalizer A library that helps you read text from an unknown charset encoding. Motivated by original Python version of charset-normalizer, I'

Rust version of webpack/enhanced-resolve
Rust version of webpack/enhanced-resolve

Oxc Resolver Rust port of enhanced-resolve. built-in tsconfig-paths-webpack-plugin support extending tsconfig defined in tsconfig.extends support path

A simple Rust version of goctl

goctl-rs A simple Rust version of goctl Support type struct many type struct nest type struct service block API block Structure token.rs - Tokenize th

Experimental Rust UI library for Audulus. "rui" is a temporary name.

Experimental Rust UI library for Audulus. "rui" is a temporary name.

Experimental language build in Rust to make it fast and robust

Reg-lang Experimental language build with Rust. Its aim is : To be simple to help learning programmation with, and in a second hand, to be robust enou

An experimental GUI library for Rust 🦀

guee 🚧 Nothing to see here 🚧 ... But if you insist: This is an experimental UI library I'm working on for Blackjack. The idea is to find a very prag

Owner
Wenju Gao
Wenju Gao
Run the right version of python, in the right environment, for your project

rpy Do you deal with lots of virtual python environments? rpy is for you! Before rpy: ~/dev/prj$ env PYTHONPATH=src/py path/to/my/interpreter src/py/m

Aquatic Capital Management 2 Dec 8, 2022
A community improved version of the polycubes project!

Polycubes This code is associated with the Computerphile video on generating polycubes. The original repository may be found here. That version is unc

Michael Pound 30 Jul 26, 2023
SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project.

SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project. With just a few primary configurations, such as project name, you can get started quickly.

Gabriel Michaliszen 4 May 9, 2023
Experimental engine agnostic 3D CSG library for game development written in Rust. Started as a port of csg.js to Rust.

brusher Experimental engine agnostic 3D CSG library for game development written in Rust. Started as a port of csg.js to Rust. ultimate goal My hope i

Brian Howard 17 Sep 4, 2024
An over-simplified version control system written in Rust, similar to Git, for local files (Incomplete)

Vault Vault will be a command line tool (if successful) similar to git which would have multiple features like brances etc etc. __ __ _ _

Shubham 3 Nov 21, 2023
An experimental real-time operating system (RTOS) written in Rust

An experimental real-time operating system (RTOS) written in Rust

null 0 Nov 14, 2022
Cuprate, an upcoming experimental, modern & secure monero node. Written in Rust

Cuprate an upcoming experimental, modern & secure monero node. Written in Rust (there is nothing working at the moment, stay tuned if you want to see

Someone Else 16 Feb 20, 2023
🛠️ An experimental functional systems programming language, written in Rust and powered by LLVM as a backend.

An experimental functional systems programming language, written in Rust, and powered by LLVM as a backend. ?? Goal: The intent is to create a program

codex 3 Nov 15, 2023
A more intuitive version of du in rust

A more intuitive version of du in rust

andy.boot 3k Sep 20, 2021
Vyper-Compiler Version Manager in Rust

Vyper Compiler Version Manager in Rust Install $ cargo install --git https://github.com/storming0x/vvm-rs --locked vvm-rs Install from source $ git c

Storming0x 26 Dec 15, 2022