Integra is a sleek, performant web framework for Rust, harnessing the power of the hyper
library.
hyper
, one of the Rust's fastest web libraries.Create a New Project: Start by creating a new Rust project.
toml
cargo new integra_project
cd integra_project
Add Dependencies: Open Cargo.toml
and add the following lines under [dependencies]
:
toml
[dependencies]
integra = { version = "0.0.4" }
tokio = { version = "1", features = ["full"] }
hyper = "0.14"
Setup Your Server: In src/main.rs
, you can use the following template to set up a basic server:
```rust
use integra::core::router::ROUTER;
use hyper::{Server, Body, Request, Response};
use std::convert::Infallible;
mod web;
async fn main() { web::initialize_routes();
let makesvc = makeservicefn(move |conn| { async move { Ok::<_, Infallible>(service_fn(ROUTER.route)) } });
let addr = ([127, 0, 0, 1], 3000).into(); let server = Server::bind(&addr).serve(make_svc);
println!("Server running on http://{}", addr);
if let Err(e) = server.await { eprintln!("Server error: {}", e); } } ```
Define Your Routes: In the web
module (usually a file named web.rs
in the root), use Integra's routing system:
```rust
use crate::app::{index, greet};
use integra::core::router::Route;
pub fn initialize_routes() { Route::get("/", index); Route::get("/hello", greet); } ```
Define Your App: In the app
module (usually a file named app.rs
in the root):
```rust
use hyper::{Body, Request, Response};
use std::pin::Pin;
use std::future::Future;
pub fn index(_req: Request
) -> Pinpub fn greet(_req: Request
) -> PinTo-do
To-do