ruvel 0.7.1

The laravel alternative framework with rust performance
Documentation
use super::into_middleware::IntoMiddleware;
use super::pending_resource_registrar::PendingResourceRegistration;
use super::pending_route_registrar::PendingRouteRegistrar;
use crate::contracts::support::Responsable;
use crate::http::{Controller, Method, Request};
use std::future::Future;

/// Trait defining the fluent route registration and attribute configuration surface
/// for [`Router`](super::Router).
pub trait RouteRegistrar {
    /// Register a new GET route with the router.
    fn get<F, Fut, R>(&mut self, path: &str, handler: F) -> PendingRouteRegistrar<'_>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: Responsable;

    /// Register a new POST route with the router.
    fn post<F, Fut, R>(&mut self, path: &str, handler: F) -> PendingRouteRegistrar<'_>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: Responsable;

    /// Register a new PUT route with the router.
    fn put<F, Fut, R>(&mut self, path: &str, handler: F) -> PendingRouteRegistrar<'_>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: Responsable;

    /// Register a new PATCH route with the router.
    fn patch<F, Fut, R>(&mut self, path: &str, handler: F) -> PendingRouteRegistrar<'_>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: Responsable;

    /// Register a new DELETE route with the router.
    fn delete<F, Fut, R>(&mut self, path: &str, handler: F) -> PendingRouteRegistrar<'_>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: Responsable;

    /// Register a new route that responds to all standard HTTP methods.
    fn any<F, Fut, R>(&mut self, path: &str, handler: F) -> PendingRouteRegistrar<'_>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: Responsable;

    /// Register a new route that responds to the given HTTP methods.
    fn r#match<F, Fut, R>(
        &mut self,
        methods: &[Method],
        path: &str,
        handler: F,
    ) -> PendingRouteRegistrar<'_>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: Responsable;

    /// Begin configuring a route or group with a domain constraint.
    fn domain(&mut self, domain: impl Into<String>) -> PendingRouteRegistrar<'_>;

    /// Begin configuring a route or group with a path prefix.
    fn prefix(&mut self, prefix: impl Into<String>) -> PendingRouteRegistrar<'_>;

    /// Begin configuring a route or group with a route name or name prefix.
    fn name(&mut self, name: impl Into<String>) -> PendingRouteRegistrar<'_>;

    /// Begin configuring a route or group with middleware.
    fn middleware(&mut self, middleware: impl IntoMiddleware) -> PendingRouteRegistrar<'_>;

    /// Begin configuring a route or group with excluded middleware aliases/groups.
    fn without_middleware(&mut self, middleware: impl IntoMiddleware) -> PendingRouteRegistrar<'_>;

    /// Register a resource controller responding to standard CRUD actions.
    fn resource<C: Controller + 'static>(
        &mut self,
        name: &str,
        controller: C,
    ) -> PendingResourceRegistration<'_>;

    /// Register an API resource controller (omitting `create` and `edit` form actions).
    fn api_resource<C: Controller + 'static>(
        &mut self,
        name: &str,
        controller: C,
    ) -> PendingResourceRegistration<'_> {
        self.resource(name, controller).except(&["create", "edit"])
    }
}