Skip to main content

Router

Struct Router 

Source
pub struct Router<S = ()> { /* private fields */ }
Expand description

Lumina Router — fluent builder API yang membungkus axum::Router.

Implementations§

Source§

impl<S> Router<S>
where S: Clone + Send + Sync + 'static,

Source

pub fn new() -> Router<S>

Buat router baru yang kosong.

Source

pub fn from_axum(inner: Router<S>) -> Router<S>

Buat Lumina Router dari axum::Router yang sudah ada.

Source

pub fn prefix(self, prefix: &str) -> Router<S>

Tentukan prefix untuk semua route yang didaftarkan setelah ini.

Source

pub fn get<H, T>(self, path: &str, handler: H) -> Router<S>
where H: Handler<T, S>, T: 'static,

Daftarkan route GET.

Source

pub fn post<H, T>(self, path: &str, handler: H) -> Router<S>
where H: Handler<T, S>, T: 'static,

Daftarkan route POST.

Source

pub fn put<H, T>(self, path: &str, handler: H) -> Router<S>
where H: Handler<T, S>, T: 'static,

Daftarkan route PUT.

Source

pub fn delete<H, T>(self, path: &str, handler: H) -> Router<S>
where H: Handler<T, S>, T: 'static,

Daftarkan route DELETE.

Source

pub fn patch<H, T>(self, path: &str, handler: H) -> Router<S>
where H: Handler<T, S>, T: 'static,

Daftarkan route PATCH.

Source

pub fn summary(self, summary: impl Into<String>) -> Router<S>

Tambahkan ringkasan (summary) untuk route terakhir yang didaftarkan (OpenAPI).

Source

pub fn description(self, description: impl Into<String>) -> Router<S>

Tambahkan deskripsi lengkap untuk route terakhir yang didaftarkan (OpenAPI).

Source

pub fn tag(self, tag: impl Into<String>) -> Router<S>

Tambahkan satu kategori/tag untuk route terakhir (OpenAPI).

Source

pub fn tags(self, tags: &[&str]) -> Router<S>

Tambahkan banyak tag untuk route terakhir (OpenAPI).

Source

pub fn deprecated(self) -> Router<S>

Tandai route terakhir sebagai usang / deprecated (OpenAPI).

Source

pub fn operation_id(self, id: impl Into<String>) -> Router<S>

Tetapkan operationId unik untuk route terakhir (OpenAPI).

Source

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).

Source

pub fn group<F>(self, prefix: &str, f: F) -> Router<S>
where F: FnOnce(Router<S>) -> 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)
})
Source

pub fn merge(self, other: Router<S>) -> Router<S>

Gabungkan dengan Router lain.

Source

pub fn nest(self, prefix: &str, other: Router<S>) -> Router<S>

Nest router lain di bawah prefix tertentu.

Source

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.

Source

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.

Source

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)
Source

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.

Source

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(...).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn security_headers(self) -> Router<S>

Tambahkan security headers standar industri (OWASP) ke semua route pada router ini.

Source

pub fn routes_doc(&self) -> Vec<RouteDoc>

Dapatkan daftar metadata route yang didaftarkan untuk OpenAPI

Source

pub fn openapi_spec(&self, title: &str, version: &str) -> OpenApiSpec

Menghasilkan struktur OpenApiSpec lengkap dari seluruh route yang terdaftar

Source

pub fn openapi_json(&self, title: &str, version: &str) -> String

Menghasilkan string JSON OpenAPI v3.0 yang rapi

Source

pub fn openapi_yaml(&self, title: &str, version: &str) -> String

Menghasilkan string YAML OpenAPI v3.0

Source

pub fn export_openapi_json( &self, path: impl AsRef<Path>, title: &str, version: &str, ) -> Result<(), Error>

Ekspor spesifikasi OpenAPI ke file JSON

Source

pub fn export_openapi_yaml( &self, path: impl AsRef<Path>, title: &str, version: &str, ) -> Result<(), Error>

Ekspor spesifikasi OpenAPI ke file YAML

Source

pub fn export_postman( &self, path: impl AsRef<Path>, collection_name: &str, version: &str, ) -> Result<(), Error>

Ekspor koleksi Postman v2.1 ke file JSON

Source

pub fn swagger_ui( self, mount_path: &str, title: &str, version: &str, ) -> Router<S>
where S: Clone + Send + Sync + 'static,

Pasang Swagger UI interaktif dan endpoint OpenAPI JSON secara otomatis.

Menyediakan:

  • GET {mount_path} dan GET {mount_path}/swagger: Antarmuka visual Swagger UI
  • GET {mount_path}/openapi.json: Spesifikasi OpenAPI v3 mentah berformat JSON

Contoh:

ⓘ
router.swagger_ui("/docs", "Lumina API Documentation", "1.0.0")
Source

pub fn into_axum(self) -> Router<S>

Konsumsi Router ini menjadi axum::Router beserta seluruh layer middleware-nya.

Trait Implementations§

Source§

impl<S> Clone for Router<S>
where S: Clone,

Source§

fn clone(&self) -> Router<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S> Default for Router<S>
where S: Clone + Send + Sync + 'static,

Source§

fn default() -> Router<S>

Returns the “default value” for a type. Read more

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>
where Router<S>: Freeze, Vec<Arc<dyn Fn(Router<S>) -> Router<S> + Send + Sync>>: Freeze,

§

impl<S> Move for Router<S>

§

impl<S> Send for Router<S>
where Router<S>: Send, Vec<Arc<dyn Fn(Router<S>) -> Router<S> + Send + Sync>>: Send,

§

impl<S> Sync for Router<S>
where Router<S>: Sync, Vec<Arc<dyn Fn(Router<S>) -> Router<S> + Send + Sync>>: Sync,

§

impl<S> Unpin for Router<S>
where Router<S>: Unpin, Vec<Arc<dyn Fn(Router<S>) -> Router<S> + Send + Sync>>: Unpin,

§

impl<S> UnsafeUnpin for Router<S>
where Router<S>: UnsafeUnpin, Vec<Arc<dyn Fn(Router<S>) -> Router<S> + Send + Sync>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more