A web api framework with speed and safety in mind.
One of the big goals is to catch all errors at compile time
, if possible.
The framework uses hyper and ideally, the performance should be as if you were using hyper
yourself.
The framework also uses shaku for compile time
verifiable dependency injection.
All feedback is appreciated.
A simple example
Cargo.toml
[dependencies]
darpi = {git = "https://github.com/petar-dambovaliev/darpi.git", branch = "master"}
serde = { version = "1.0", features = ["derive"] }
tokio = {version = "0.2.11", features = ["full"]}
shaku = {version = "0.5.0", features = ["thread_safe"]}
main.rs
```rust
use darpi::{
app, handler, middleware, middleware::Expect, pathtype, querytype, request::ExtractBody,
Body, Method, Path,
};
use darpimiddleware::bodysizelimit;
use darpiweb::Json;
use serde::{Deserialize, Serialize};
use shaku::module;
use std::convert::Infallible;
pub async fn hellomiddleware(b: &Body, handler: Expect<&str>) -> Result<(), Infallible> {
println!("hello middleware from {}
", handler.intoinner());
Ok(())
}
pub struct Name { name: String, }
// the handler macro has 2 optional arguments
// the shaku container type and a collection of middlewares
// the enum variant Admin
is corresponding to the middlewre access_control
's Expecthello_middleware
// it is being passed on matching the handler: Expect<&str>
argument
// then we use the builtin bodysizelimit middleware and we limit the body size
// to 64 bytes
async fn do_something(p: Path
module! { Container { components = [], providers = [], } }
fn make_container() -> Container { let module = Container::builder().build(); module }
async fn main() -> Result<(), darpi::Error> {
let address = format!("127.0.0.1:{}", 3000);
app!({
address: address,
module: makecontainer => Container,
bind: [
{
route: "/helloworld/{name}",
method: Method::POST,
// the POST method allows this handler to have
// Json
```