A fast and lightweight HTTP server implementation in Rust.

Overview

server_nano

A tiny, fast, and friendly web server written in rust and inspired by express. It uses may to coroutines

Usage

First, add this to your Cargo.toml:

[dependencies]
server_nano = "0.1.4"

Now, you can write you server

use server_nano::{json, Server};

fn main() {
    let mut app = Server::new();

    app.get("/", |_, res| res.send("welcome to home page!"));

    app.get("/user/:id", |req, res| {
        let user_id = req.parameter("id").unwrap();
        let json_value = json!({ "username": user_id });
        res.json(&json_value)
    });

    app.get("/product/:name", |req, res| {
        let product_name = req.parameter("name").unwrap();
        let message = &format!("Welcome to product page of product: {}", product_name);
        res.send(message)
    });

    app.post("/test", |_, res| res.send("test!"));

    app.post("/settings", |req, res| {
        let json_body = req.json_body().unwrap();

        let response = json!({
            "success": true,
            "message": "Settings updated successfully",
            "body": json_body
        });
        res.json(&response)
    });

    app.listen("127.0.0.1:8080").unwrap();
}
You might also like...
A blazingly fast & lightweight Obsidian CLI ⚡️
A blazingly fast & lightweight Obsidian CLI ⚡️

obs - the Obsidian CLI ⚡️ Connecting your second brain to the termainl - blazing fast ⚡️ Note 🚧 obs is under active development and currently only su

Lightweight & Fast LWW CRDT Table

Lightweight & Fast LWW CRDT Table Supports millions of operations per second Suitable for real-time collaboration Supports delta updates It is a CRDT,

A lightweight and high-performance order-book designed to process level 2 and trades data. Available in Rust and Python

ninjabook A lightweight and high-performance order-book implemented in Rust, designed to process level 2 and trades data. Available in Python and Rust

Bruteforce connecting to a specific Sea of Thieves server. Useful if you want to be in the same server as your friends.

SoT Server Finder Find which Sea of Thieves server you're connected to. Useful if you want to be in the same server as your friends. Setup Download so

Leptos server signals synced through Server-Sent-Events (SSE)

Leptos Server Sent Events Server signals are leptos signals kept in sync with the server through server-sent-events (SSE). The signals are read-only o

A blazing fast and easy to use TRPC-like server for Rust.

rspc 🚧 Work in progress 🚧 A blazing fast and easy to use TRPC-like server for Rust. Website Example You define a trpc router and attach resolvers to

Minimal and blazing-fast file server. For real, this time.

Zy Minimal and blazing-fast file server. For real, this time. Features Single Page Application support Partial responses (Range support) Cross-Origin

A fast nostr opengraph server, built on nostrdb and egui.
A fast nostr opengraph server, built on nostrdb and egui.

notecrumbs A nostr opengraph server build on nostrdb, egui, and skia. It renders notes using the CPU in around 50ms. Status WIP! Local note fetching w

A simple, fast, and easy to use static file server

Warning This is still in early development, I would not recommend for production use.. yet. See the issues for things that are on the "roadmap" or mis

Comments
  • the example does not work

    the example does not work

    Hi, When I run the example, I get this error:

    error[E0599]: no method named `call` found for type parameter `T` in the current scope
       --> C:\Users\Arthur\.cargo\registry\src\github.com-1ecc6299db9ec823\server_nano-0.1.4\src\http\http_server.rs:136:31
        |
    114 | fn each_connection_loop<T: HttpService>(stream: &mut TcpStream, mut service: T) -> io::Result<()> {
        |                         - method `call` not found for this type parameter
    ...
    136 |                 match service.call(req, &mut res) {
        |                               ^^^^ method not found in `T`
        |
        = help: items from traits can only be used if the type parameter is bounded by the trait
    help: the following trait defines an item `call`, perhaps you need to restrict type parameter `T` with it:
        |
    114 | fn each_connection_loop<T: HttpService + Fn>(stream: &mut TcpStream, mut service: T) -> io::Result<()> {
        |                                        ++++
    
    For more information about this error, try `rustc --explain E0599`.
    error: could not compile `server_nano` due to previous error
    warning: build failed, waiting for other jobs to finish...
    
    opened by MoskalykA 3
Owner
Jonny Borges
VP of Engineering from Iris Finance. Developer and Lawyer. Passionate about dart and productivity hacks.
Jonny Borges
A lightweight but incredibly powerful and feature-rich BitTorrent tracker. Supports UDP + HTTP(S) and a private tracker mode.

Torrust Tracker Project Description Torrust Tracker is a lightweight but incredibly powerful and feature-rich BitTorrent tracker made using Rust. Feat

Torrust 162 Dec 31, 2022
Spoon Radio Echo Project, Lightweight and scalable broadcasting server.

Echo Project https://medium.com/p/3bd1434a163a Echo was initiated by a social network platform, Spoon Radio(https://www.spooncast.net). The main goal

Spoon Radio Inc. 23 Jan 3, 2023
Minimal server (with maximal security) for turning off an X10-controlled fan over HTTP

"Fan Remote" A self-contained Rust binary to expose a single X10 command (turn off that fan) as an HTML form button. In its current form, it's highly

Stephan Sokolow 2 Oct 23, 2022
A lightweight ShareX-compatible image uploader server

Imitari Imitari is a project to provide an easy and lightweight server for images. It is compatible with software like ShareX. The projects goals are

Imitari 12 May 5, 2022
A lightweight and super fast cli todo program written in rust under 200 sloc

todo A lightweight and super fast cli todo program written in rust under 200 sloc installation AUR package: todo-bin use cargo build --release to comp

sioodmy 243 Dec 24, 2022
A fast, simple and lightweight Bloom filter library for Python, fully implemented in Rust.

rBloom A fast, simple and lightweight Bloom filter library for Python, fully implemented in Rust. It's designed to be as pythonic as possible, mimicki

Kenan Hanke 91 Feb 4, 2023
An easy, fast and lightweight tool to create notes in terminal.

An easy and lightweight tool to create notes in terminal. Features Make notes faster. Manage your notes directly in terminal. Lightweight and fast. Ea

Konstantin Zhigaylo 5 May 24, 2023
A self-contained, unopinionated, fast and lightweight executable launcher.

Kickoff ?? A self-contained, unopinionated, fast and lightweight executable launcher. Supported Platforms Platform Host Target aarch64-apple-macos-non

Nimbus 18 Oct 27, 2023
⚡ Blazing fast async/await HTTP client for Python written on Rust using reqwests

Reqsnaked Reqsnaked is a blazing fast async/await HTTP client for Python written on Rust using reqwests. Works 15% faster than aiohttp on average RAII

Yan Kurbatov 8 Mar 2, 2023
A safe, fast, lightweight embeddable scripting language written in Rust.

Bud (budlang) A safe, fast, lightweight embeddable scripting language written in Rust. WARNING: This crate is not anywhere near being ready to publish

Khonsu Labs 13 Dec 27, 2022