pub struct Router<S = ()> { /* private fields */ }Expand description
Lumina Router — fluent builder API yang membungkus axum::Router.
Implementations§
Source§impl<S> Router<S>
impl<S> Router<S>
Sourcepub fn from_axum(inner: Router<S>) -> Router<S>
pub fn from_axum(inner: Router<S>) -> Router<S>
Buat Lumina Router dari axum::Router yang sudah ada.
Sourcepub fn prefix(self, prefix: &str) -> Router<S>
pub fn prefix(self, prefix: &str) -> Router<S>
Tentukan prefix untuk semua route yang didaftarkan setelah ini.
Sourcepub fn get<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
pub fn get<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
Daftarkan route GET.
Sourcepub fn post<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
pub fn post<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
Daftarkan route POST.
Sourcepub fn put<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
pub fn put<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
Daftarkan route PUT.
Sourcepub fn delete<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
pub fn delete<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
Daftarkan route DELETE.
Sourcepub fn patch<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
pub fn patch<H, T>(self, path: &str, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
Daftarkan route PATCH.
Sourcepub fn summary(self, summary: impl Into<String>) -> Router<S>
pub fn summary(self, summary: impl Into<String>) -> Router<S>
Tambahkan ringkasan (summary) untuk route terakhir yang didaftarkan (OpenAPI).
Sourcepub fn description(self, description: impl Into<String>) -> Router<S>
pub fn description(self, description: impl Into<String>) -> Router<S>
Tambahkan deskripsi lengkap untuk route terakhir yang didaftarkan (OpenAPI).
Sourcepub fn tag(self, tag: impl Into<String>) -> Router<S>
pub fn tag(self, tag: impl Into<String>) -> Router<S>
Tambahkan satu kategori/tag untuk route terakhir (OpenAPI).
Tambahkan banyak tag untuk route terakhir (OpenAPI).
Sourcepub fn deprecated(self) -> Router<S>
pub fn deprecated(self) -> Router<S>
Tandai route terakhir sebagai usang / deprecated (OpenAPI).
Sourcepub fn operation_id(self, id: impl Into<String>) -> Router<S>
pub fn operation_id(self, id: impl Into<String>) -> Router<S>
Tetapkan operationId unik untuk route terakhir (OpenAPI).
Sourcepub fn fallback<H, T>(self, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
pub fn fallback<H, T>(self, handler: H) -> Router<S>where
H: Handler<T, S>,
T: 'static,
Daftarkan fallback handler (misal untuk menangani 404 Not Found).
Sourcepub fn group<F>(self, prefix: &str, f: F) -> Router<S>
pub fn group<F>(self, prefix: &str, f: F) -> Router<S>
Grup route dengan prefix dan kustomisasi (seperti middleware). Contoh:
router.group("/admin", |r| {
r.middleware(from_fn(admin_auth))
.get("/dashboard", dashboard_handler)
})Sourcepub fn nest(self, prefix: &str, other: Router<S>) -> Router<S>
pub fn nest(self, prefix: &str, other: Router<S>) -> Router<S>
Nest router lain di bawah prefix tertentu.
Sourcepub fn layer<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn layer<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
Tambahkan middleware (layer) ke router. Middleware ini akan diterapkan ke semua route yang ada di router ini saat dibuild.
Sourcepub fn middleware<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn middleware<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
Alias untuk layer agar lebih familiar bagi pengguna Laravel.
Sourcepub fn guard<F, T>(self, f: F) -> Router<S>where
F: Clone + Send + Sync + 'static,
FromFnLayer<F, (), T>: Layer<Route> + Clone + Send + Sync + 'static,
<FromFnLayer<F, (), T> as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn guard<F, T>(self, f: F) -> Router<S>where
F: Clone + Send + Sync + 'static,
FromFnLayer<F, (), T>: Layer<Route> + Clone + Send + Sync + 'static,
<FromFnLayer<F, (), T> as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
Daftarkan async middleware function secara langsung tanpa perlu from_fn(...).
Contoh:
async fn auth_guard(req: Request, next: Next) -> Response {
next.run(req).await
}
Router::new()
.guard(auth_guard)
.get("/protected", handler)Sourcepub fn middleware_fn<F, T>(self, f: F) -> Router<S>where
F: Clone + Send + Sync + 'static,
FromFnLayer<F, (), T>: Layer<Route> + Clone + Send + Sync + 'static,
<FromFnLayer<F, (), T> as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn middleware_fn<F, T>(self, f: F) -> Router<S>where
F: Clone + Send + Sync + 'static,
FromFnLayer<F, (), T>: Layer<Route> + Clone + Send + Sync + 'static,
<FromFnLayer<F, (), T> as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
Alias untuk guard agar konsisten dengan middleware_fn.
Sourcepub fn route_guard<F, T>(self, f: F) -> Router<S>where
F: Clone + Send + Sync + 'static,
FromFnLayer<F, (), T>: Layer<Route> + Clone + Send + Sync + 'static,
<FromFnLayer<F, (), T> as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn route_guard<F, T>(self, f: F) -> Router<S>where
F: Clone + Send + Sync + 'static,
FromFnLayer<F, (), T>: Layer<Route> + Clone + Send + Sync + 'static,
<FromFnLayer<F, (), T> as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<FromFnLayer<F, (), T> as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
Daftarkan async middleware function pada route-level tanpa perlu from_fn(...).
Sourcepub fn route_layer<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn route_layer<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
Tambahkan route-level middleware (hanya berlaku untuk route pada router ini).
Sourcepub fn route_middleware<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn route_middleware<L>(self, layer: L) -> Router<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
<L as Layer<Route>>::Service: Service<Request<Body>> + Clone + Send + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<!> + 'static,
<<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send + 'static,
Alias untuk route_layer agar familiar bagi pengguna Laravel.
Sourcepub fn can(self, permission: &'static str) -> Router<S>
pub fn can(self, permission: &'static str) -> Router<S>
Lindungi semua route pada router ini dengan pengecekan izin (Permission). Mengembalikan 401 Unauthorized jika belum login, atau 403 Forbidden jika tidak punya izin.
Sourcepub fn has_role(self, role: &'static str) -> Router<S>
pub fn has_role(self, role: &'static str) -> Router<S>
Lindungi semua route pada router ini dengan pengecekan peran (Role). Mengembalikan 401 Unauthorized jika belum login, atau 403 Forbidden jika role tidak sesuai.
Sourcepub fn panic_boundary(self) -> Router<S>
pub fn panic_boundary(self) -> Router<S>
Lindungi route dengan Zero-Panic Error Boundary. Menjamin bahwa panic di dalam handler tidak akan pernah meruntuhkan server.
Sourcepub fn security_headers(self) -> Router<S>
pub fn security_headers(self) -> Router<S>
Tambahkan security headers standar industri (OWASP) ke semua route pada router ini.
Sourcepub fn routes_doc(&self) -> Vec<RouteDoc>
pub fn routes_doc(&self) -> Vec<RouteDoc>
Dapatkan daftar metadata route yang didaftarkan untuk OpenAPI
Sourcepub fn openapi_spec(&self, title: &str, version: &str) -> OpenApiSpec
pub fn openapi_spec(&self, title: &str, version: &str) -> OpenApiSpec
Menghasilkan struktur OpenApiSpec lengkap dari seluruh route yang terdaftar
Sourcepub fn openapi_json(&self, title: &str, version: &str) -> String
pub fn openapi_json(&self, title: &str, version: &str) -> String
Menghasilkan string JSON OpenAPI v3.0 yang rapi
Sourcepub fn openapi_yaml(&self, title: &str, version: &str) -> String
pub fn openapi_yaml(&self, title: &str, version: &str) -> String
Menghasilkan string YAML OpenAPI v3.0
Sourcepub fn export_openapi_json(
&self,
path: impl AsRef<Path>,
title: &str,
version: &str,
) -> Result<(), Error>
pub fn export_openapi_json( &self, path: impl AsRef<Path>, title: &str, version: &str, ) -> Result<(), Error>
Ekspor spesifikasi OpenAPI ke file JSON
Sourcepub fn export_openapi_yaml(
&self,
path: impl AsRef<Path>,
title: &str,
version: &str,
) -> Result<(), Error>
pub fn export_openapi_yaml( &self, path: impl AsRef<Path>, title: &str, version: &str, ) -> Result<(), Error>
Ekspor spesifikasi OpenAPI ke file YAML
Sourcepub fn export_postman(
&self,
path: impl AsRef<Path>,
collection_name: &str,
version: &str,
) -> Result<(), Error>
pub fn export_postman( &self, path: impl AsRef<Path>, collection_name: &str, version: &str, ) -> Result<(), Error>
Ekspor koleksi Postman v2.1 ke file JSON
Sourcepub fn swagger_ui(
self,
mount_path: &str,
title: &str,
version: &str,
) -> Router<S>
pub fn swagger_ui( self, mount_path: &str, title: &str, version: &str, ) -> Router<S>
Pasang Swagger UI interaktif dan endpoint OpenAPI JSON secara otomatis.
Menyediakan:
GET {mount_path}danGET {mount_path}/swagger: Antarmuka visual Swagger UIGET {mount_path}/openapi.json: Spesifikasi OpenAPI v3 mentah berformat JSON
Contoh:
router.swagger_ui("/docs", "Lumina API Documentation", "1.0.0")Trait Implementations§
Auto Trait Implementations§
impl<S = ()> !RefUnwindSafe for Router<S>
impl<S = ()> !UnwindSafe for Router<S>
impl<S> Forget for Router<S>
impl<S> Freeze for Router<S>
impl<S> Move for Router<S>
impl<S> Send for Router<S>
impl<S> Sync for Router<S>
impl<S> Unpin for Router<S>
impl<S> UnsafeUnpin for Router<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().