Expand description
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_projcdinto my_projcargo runto 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§Discord server link:
§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 Stats | Avg | Stdev | Max | +/- Stdev |
|---|---|---|---|---|
| Latency | 844.10us | 480.14us | 4.14ms | 64.85% |
| Req/Sec | 26.24k | 831.40 | 28.10k | 70.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:
-
Please support rohanasan: https://www.buymeacoffee.com/rohanvashisht
-
Please star rohanasan’s github repo: https://github.com/rohanasan/rohanasan-rs
§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§
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: