Crate rohanasan

Crate rohanasan 

Source
Expand description

§Rohanasan

§An extremely fast backend framework built for rust

Minimum Supported Rust Version Crates.io Docs.rs Code Size Maintained License

Made with Performance, optimization and ease of use in mind.

Currently available in C/C++/Rust programming languages only.

This library has been built from scratch using tokio.

§Basic hello world example:

Basic Html implementation of hello world:

use rohanasan::{
    rohanasan, send_http_response, serve, Request, DEFAULT_HTML_HEADER,
};

fn handle(req: Request) -> String {
    send_http_response(DEFAULT_HTML_HEADER, "<h1>Hello!</h1>", req)
}

fn main() {
    rohanasan! {
        serve(8080, handle)
    }
}

§How to use in your project?

  • Open terminal inside the parent folder where you would like to create the folder of your project
  • Run:
cargo install rohanasanpm
rohanasanpm new my_proj
  • cd into my_proj
  • cargo run to run your project.
  • Go to: localhost:8080.
  • Enjoy using Rohanasan!

§How to run the example?

git clone https://github.com/rohanasan/rohanasan-rs.git
cd rohanasan-rs
cd examples
cargo run --example standard

https://discord.gg/Yg2A3mEret

§Performance:

§Machine Specs:

OS: Garuda Linux x86_64

Laptop: Dell Inspiron 5590

Kernel: 6.8.1-zen1-1-zen

Mode: GUI mode (terminal was running like a window)

Shell: fish 3.7.0

Terminal: konsole 24.2.1

CPU: Intel(R) Core(TM) i3-10110U (4) @ 4.10 GHz

GPU: Intel UHD Graphics (The CPU itself)

Memory: 11.47 GiB

Command used to run test: wrk -t 2 -c 100 http://localhost:8080

§Results:

Thread StatsAvgStdevMax+/- Stdev
Latency844.10us480.14us4.14ms64.85%
Req/Sec26.24k831.4028.10k70.00%

Output: 522523 requests in 10.02s, 46.84MB read

Requests/sec: 52142.29

Transfer/sec: 4.67MB

Program that was run: examples/hello_world.rs

§Current Features:

  • Can run a server at a specified port
  • Can serve a folder named static at /static
  • Can send files as http response
  • Can give you the path, method and protocol

§TODO:

  • Add feature to change the directory path of the public folder ☑️ Done!!!!
  • Asynchronous file request handling ☑️ Done!!!!
  • Add feature to give the user an option to add index.html to static folder ☑️ Done!!!!
  • Add feature of request.post_request()
  • Add feature to… currently it’s just a pre alpha release I have to add a lot of features right now!

§Contribute:

§Examples

  • Hello world (Html File):

Basic Html implementation of hello world:

use rohanasan::{
    rohanasan, send_file, serve, Request, DEFAULT_HTML_HEADER,
};
fn handle(req: Request) -> String {
    send_file(DEFAULT_HTML_HEADER, "./html/index.html", req)
}

fn main() {
    rohanasan! {
        serve(8080, handle)
    }
}

§Points to remember:

  • There is no need to import tokio for using rohanasan macro.
  • By default, rohanasan serves any folder named static present in the same directory where you are running the server.

Macros§

rohanasan
Rohanasan macro

Structs§

Builder
Builds Tokio Runtime with custom configuration values.
Request
Request Struct

Constants§

DEFAULT_204_HEADER
This is the Default 204 No Content’s Header.
DEFAULT_400_HEADER
This is the Default 400 Bad Request’s Header.
DEFAULT_401_HEADER
This is the Default 401 Unauthorized’s Header.
DEFAULT_402_HEADER
This is the Default 402 Payment Required’s Header.
DEFAULT_403_HEADER
This is the Default 403 Forbidden’s Header.
DEFAULT_404_HEADER
This is the Default 404 Not Found’s Header.
DEFAULT_405_HEADER
This is the Default 405 Method Not Allowed’s Header.
DEFAULT_406_HEADER
This is the Default 406 Not Acceptable’s Header.
DEFAULT_407_HEADER
This is the Default 407 Proxy Authentication Required’s Header.
DEFAULT_408_HEADER
This is the Default 408 Request Timeout’s Header.
DEFAULT_409_HEADER
This is the Default 409 Conflict’s Header.
DEFAULT_410_HEADER
This is the Default 410 Gone’s Header.
DEFAULT_411_HEADER
This is the Default 411 Length Required’s Header.
DEFAULT_412_HEADER
This is the Default 412 Precondition Failed’s Header.
DEFAULT_413_HEADER
This is the Default 413 Payload Too Large’s Header.
DEFAULT_414_HEADER
This is the Default 414 URI Too Long’s Header.
DEFAULT_415_HEADER
This is the Default 415 Unsupported Media Type’s Header.
DEFAULT_416_HEADER
This is the Default 416 Range Not Satisfiable’s Header.
DEFAULT_417_HEADER
This is the Default 417 Expectation Failed’s Header.
DEFAULT_418_HEADER
This is the Default 418 I’m a teapot’s Header.
DEFAULT_421_HEADER
This is the Default 421 Misdirected Request’s Header.
DEFAULT_422_HEADER
This is the Default 422 Unprocessable Entity’s Header.
DEFAULT_423_HEADER
This is the Default 423 Locked’s Header.
DEFAULT_424_HEADER
This is the Default 424 Failed Dependency’s Header.
DEFAULT_425_HEADER
This is the Default 425 Too Early’s Header.
DEFAULT_426_HEADER
This is the Default 426 Upgrade Required’s Header.
DEFAULT_428_HEADER
This is the Default 428 Precondition Required’s Header.
DEFAULT_429_HEADER
This is the Default 429 Too Many Requests’s Header.
DEFAULT_431_HEADER
This is the Default 431 Request Header Fields Too Large’s Header.
DEFAULT_451_HEADER
This is the Default 451 Unavailable For Legal Reasons’s Header.
DEFAULT_500_HEADER
This is the Default 500 Internal Server Error’s Header.
DEFAULT_501_HEADER
This is the Default 501 Not Implemented’s Header.
DEFAULT_502_HEADER
This is the Default 502 Bad Gateway’s Header.
DEFAULT_503_HEADER
This is the Default 503 Service Unavailable’s Header.
DEFAULT_504_HEADER
This is the Default 504 Gateway Timeout’s Header.
DEFAULT_505_HEADER
This is the Default 505 HTTP Version Not Supported’s Header.
DEFAULT_506_HEADER
This is the Default 506 Variant Also Negotiates’s Header.
DEFAULT_507_HEADER
This is the Default 507 Insufficient Storage’s Header.
DEFAULT_508_HEADER
This is the Default 508 Loop Detected’s Header.
DEFAULT_510_HEADER
This is the Default 510 Not Extended’s Header.
DEFAULT_511_HEADER
This is the Default 511 Network Authentication Required’s Header.
DEFAULT_HTML_HEADER
This is the Default HTML Header.
DEFAULT_JSON_HEADER
This is the Default JSON Header.
DEFAULT_PLAIN_TEXT_HEADER
This is the Default Plain Text’s Header

Functions§

send_file
Send file function:
send_file_top_bottom
Send file top bottom function:
send_http_response
Send HTTP response function:
serve
The serve function
url_decode
Url Decode function: