GithubHelp home page GithubHelp logo

rahul-bista / racoon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from racoonframework/racoon

0.0 0.0 0.0 143 KB

Racoon is a fast, fully customizable web framework for Rust focusing on simplicity.

Home Page: https://racoonframework.github.io

License: MIT License

Rust 100.00%

racoon's Introduction

Racoon

build

Racoon is a fast, fully customizable web framework for Rust focusing on simplicity.

Learn Racoon

Installation

You will need tokio runtime to run Racoon. Run cargo add tokio to install tokio crate.

[dependencies]
racoon = "0.1.1"

Basic Usage

use racoon::core::path::Path;
use racoon::core::request::Request;
use racoon::core::response::{HttpResponse, Response};
use racoon::core::response::status::ResponseStatus;
use racoon::core::server::Server;

use racoon::view;

async fn home(request: Request) -> Response {
    HttpResponse::ok().body("Home")
}

#[tokio::main]
async fn main() {
    let paths = vec![
        Path::new("/", view!(home))
    ];

    let result = Server::bind("127.0.0.1:8080")
        .urls(paths)
        .run().await;

    println!("Failed to run server: {:?}", result);
}

WebSocket example

use racoon::core::path::Path;
use racoon::core::request::Request;
use racoon::core::response::Response;
use racoon::core::server::Server;
use racoon::core::websocket::{Message, WebSocket};

use racoon::view;

async fn ws(request: Request) -> Response {
    let (websocket, connected) = WebSocket::from(&request).await;
    if !connected {
        // WebSocket connection didn't success
        return websocket.bad_request().await;
    }

    println!("WebSocket client connected.");

    // Receive incoming messages
    while let Some(message) = websocket.message().await {
        match message {
            Message::Text(text) => {
                println!("Message: {}", text);

                // Sends received message back
                let _ = websocket.send_text(text.as_str()).await;
            }
            _ => {}
        }
    }
    websocket.exit()
}

#[tokio::main]
async fn main() {
    let paths = vec![
        Path::new("/ws/", view!(ws))
        ];

    let _ = Server::bind("127.0.0.1:8080")
            .urls(paths)
            .run().await;
}

Benchmark

wrk -c8 -d4s -t4 http://127.0.0.1:8080

Result on AMD Ryzen 5 7520U with Radeon Graphics.

Running 4s test @ http://127.0.0.1:8080
  4 threads and 8 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    50.62us   60.12us   2.52ms   97.98%
    Req/Sec    40.59k     4.10k   44.20k    92.68%
  662179 requests in 4.10s, 46.73MB read
Requests/sec: 161510.26
Transfer/sec:     11.40MB

This benchmark does not make sense in real world.

racoon's People

Contributors

rahul-bista avatar tejmagar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.