Skip to main content

rustlavel_gateway/
lib.rs

1//! rustlavel-gateway: one door in front of several services.
2//!
3//! Nothing else in this framework forwards a request. The client can call out,
4//! the cache can rate-limit, `rustlavel-otel` can trace — and no code takes an
5//! inbound request, sends it on and streams the answer back. That is this
6//! crate.
7//!
8//! ```
9//! use rustlavel_gateway::{Gateway, Upstream};
10//!
11//! let gateway = Gateway::new()
12//!     .route("/api/*", Upstream::at("http://127.0.0.1:9002"))
13//!     .route("/oauth/*", Upstream::at("http://127.0.0.1:9001"))
14//!     // An upstream is anywhere, not only a service you deployed.
15//!     .route("/maps/*", Upstream::at("https://api.example.com").strip("/maps"))
16//!     // Refuse a request with no credential before it costs a hop. The
17//!     // services behind still check for themselves — see below.
18//!     .require_token();
19//!
20//! assert_eq!(gateway.routes().find("/api/orders").map(Upstream::base), Some("http://127.0.0.1:9002"));
21//! ```
22//!
23//! Hand it to an application with `.plugin(gateway)`: it registers as the
24//! router's fallback, so the application's own routes — health, metrics —
25//! are matched first and only what nothing claimed reaches the table. A
26//! gateway that swallowed every path would hide exactly the endpoints
27//! somebody needs when the services behind it are the problem.
28//!
29//!
30//! **A gateway is not the only door.** Anything on the network can reach a
31//! service directly, so the services behind this still check tokens for
32//! themselves. What the gateway saves is load, not the check: a request with no
33//! token is refused here rather than after three network hops.
34
35pub mod forward;
36pub mod health;
37pub mod gateway;
38pub mod route;
39
40pub use gateway::Gateway;
41pub use route::{Locate, Routes, Upstream};