| Crates.io | altaria |
| lib.rs | altaria |
| version | 0.4.2 |
| created_at | 2024-12-06 17:13:17.851975+00 |
| updated_at | 2024-12-20 20:24:32.178168+00 |
| description | Altaria is an asynchronous, memory-safe, blazingly fast HTTP server written in Rust. It currently supports HTTP1.1 parsing and encoding and HTTP2 parsing. |
| homepage | https://github.com/SrGaabriel/altaria |
| repository | https://github.com/SrGaabriel/altaria |
| max_upload_size | |
| id | 1474467 |
| size | 77,355 |
Altaria is an asynchronous, memory-safe, blazingly fast HTTP server written in Rust.
Roadmap:
[!IMPORTANT]
This project is made mostly for educational/learning purposes. It is not recommended to use it in production. Maybe in the future, it will be production-ready.
struct State(usize);
#[tokio::main]
async fn main() {
let handler = function_handler(|_| async {
(HttpStatusCode::OK, "Hello, World!")
});
let router = Router::new()
.add_resource("Altaria")
.add_resource(Arc::new(Mutex::new(State(0))))
.add_handler("/", handler)
.add_endpoint(endpoint!(greet))
.add_endpoint(endpoint!(count));
Server::builder()
.local_port(8080)
.router(router)
.start()
.await
.unwrap()
}
#[get("/meet/{name}?sec={secret}")]
async fn meet(
name: String,
secret: Option<String>,
Resource(me): Resource<&str>,
) -> String {
match secret {
Some(secret) => format!("I'm, {me}! Hello {name}! Your secret is {secret}"),
_ => format!("I'm, {me}! Hello, {name}!")
}
}
#[post("/count")]
async fn count(
Resource(state): Resource<SharedState>,
JsonBody(update): JsonBody<CountUpdate>
) -> JsonBody<CountUpdate> {
let mut state = state.lock().await;
state.count = update.new_count;
JsonBody(CountUpdate {
new_count: state.count
})
}