Crates.io | hyper-fast |
lib.rs | hyper-fast |
version | 0.3.5 |
source | src |
created_at | 2023-09-18 23:53:23.313324 |
updated_at | 2023-09-20 00:59:06.395801 |
description | Hyper and rust based very fast HTTP Web framework (much faster than actix and other frameworks). |
homepage | |
repository | https://github.com/hyper-fast/hyper-fast |
max_upload_size | |
id | 976378 |
size | 111,015 |
Hyper and rust based very fast HTTP Web framework (much faster than actix and other frameworks).
Look at examples/example_server.rs
for a working example. Example can be run with cargo run --example example_server
Service
trait for api routing.pub struct ExampleService {
// any service level properties
}
#[async_trait]
impl Service for ExampleService {
async fn api_handler<'a>(
&'a self,
_: Body,
route: &HttpRoute<'a>,
path: &[&str],
) -> Result<Response<Body>, ApiError> {
match path {
["test"] if matches!(route.method, &http::Method::GET) => {
self.get_test(route).await
}
_ => HttpResponse::not_found(route.path),
}
}
}
impl ExampleService {
pub async fn get_test(&self, route: &HttpRoute<'_>) -> Result<Response<Body>, ApiError> {
HttpResponse::string(route, "GET::/api/test - test passed".to_string())
}
}
pub struct ExampleServiceDaemon {}
#[async_trait]
impl ServiceDaemon<ExampleService> for ExampleServiceDaemon {
async fn start(&self, _service: Arc<ExampleService>) {
//no impl for now.
}
}
ServiceBuilder
traitpub struct ExampleServiceBuilder {
// any service builder level properties
}
#[async_trait]
impl ServiceBuilder<ExampleService, ExampleServiceDaemon> for ExampleServiceBuilder {
async fn build(self) -> anyhow::Result<(ExampleService, Option<ExampleServiceDaemon>)> {
let service = ExampleService {};
Ok((service, None))
}
}
start_http_server
in your main method.#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), anyhow::Error> {
load_config("examples/config", "dev")?;
setup_logging("examples/config/log4rs.yml")?;
start_http_server("127.0.0.1:6464", ExampleServiceBuilder {}).await
}
/oor
- switches the in-rotation status of server
/status
- gives in-rotation status of server
/metrics/json
- metrics in JSON format
/metrics/prometheus
- metrics in Prometheus format
/api/<your-api-routes>
- all your api routes are after /api