1 unstable release
0.0.1 | Oct 11, 2023 |
---|
#15 in #nova
Used in 4 crates
(2 directly)
11KB
100 lines
nova
nova_web
- a web server framework written in Rust
More information about this crate can be found in the crate documentation.
Examples of how to use the crate can be found in examples.
Crate features
- Macro-free routing handling
- serde integration for parsing request body
- [todo] Handlers registered by macros
- [todo] OpenApi support
- custom Middleware integration
- [todo] custom Dependency Injection integration
[todo] Custom middleware include pre-implemented commonly used middlewares like [middleware..].
Custom Dependency Injection provides a flexibility to control the dependencies like database connection or other external integrations.
Usage example
in Cargo.toml:
[dependencies]
nova_web = "0.0.1"
tokio = "1.32"
serde = { version = "1.0", features = ["derive"] }
use nova_web::prelude::*;
#[derive(Debug, Deserialize, Serialize)]
struct RequestBody {
id: String,
name: String,
}
fn hello_world(_: &HttpRequest, res: &mut HttpResponse) -> ServerResponse {
Ok(res
.status(HttpStatus::OK)
.body("Hello, world!".as_bytes()))
}
fn hello_json(req: &HttpRequest, res: &mut HttpResponse) -> ServerResponse {
let body: RequestBody = req.json()?;
Ok(res
.status(HttpStatus::OK)
.body(format!("Hello, {}!", body.name).as_bytes()))
}
#[tokio::main]
async fn main() -> Result<(), ServerError> {
Server::create("0.0.0.0", 3000)
.service("/hello", vec![
get("/", hello_world),
post("/json", hello_json),
].into())
.bind()
.await
}
Performance
[todo] prepare benchmarks
Safety
This crate uses restrictive linter settings on top of #![forbid(unsafe_code)]
to ensure safety and clearness of source code.
Minimum supported Rust version
MSRV
for nova
is 1.63
Examples
Usage examples can be found here. The docs also include code snippets.
[todo] More examples, snippets and information can be found on wiki.
License
The project is licensed under the Apache license or MIT license
Contribution
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion in nova
, shall be licensed as Apache or MIT, without any additional terms or conditions.
Dependencies
~1.1–2.1MB
~45K SLoC