ohkami

ohkami - [狼] means wolf in Japanese - is simple and non macro-based web framework for Rust.


Features


Quick start

  1. Add dependencies:

toml [dependencies] ohkami = "0.1"

  1. Write your first code with ohkami:

```rust use ohkami::prelude::*;

fn main() -> Result<()> { Server::setup() .GET("/", || async {Response::OK("Hello, world!")}) .serveon(":3000") } ```

  1. If you're interested in ohkami, learn more by examples and documentations(WIP)!


Snippets

get path param

rust let param: Option<&str> = ctx.param(); // current ohkami only supports single path param at the end of a path

get query param

rust let query: Option<&str> = ctx.query("key");

deserialize request body

rust let body: Result<D> = ctx.body::<D>();

return OK response with text/plain

rust Response::OK("Hello, world!")

return OK response with application/json

rust Response::OK(JSON("Hello, world!")) rust Response::OK(json!("ok": true)) rust Response::OK(json(user)?) // serialize Rust value into JSON

error handling

rust let count = ctx.query("count") ._else(|| Response::BadRequest("expected query param `count`"))? .parse::<usize>() ._else(|_| Response::BadRequest("`count` must be an integer"))?; ``rust let user = ctx.body::<User>()?; //ResponseimplementsFrom`

// or, you can add an error context message: let user = ctx.body::() .else(|e| e.errorcontext("failed to get user data"))?; ```


Development

ohkami is on very early stage now and not for producntion use.


License

This project is under MIT LICENSE (LICENSE-MIT or https://opensource.org/licenses/MIT).