pub struct RustApi { /* private fields */ }Expand description
Implementations§
Source§impl RustApi
impl RustApi
Sourcepub fn body_limit(self, limit: usize) -> Self
pub fn body_limit(self, limit: usize) -> Self
Set the global body size limit for request bodies
This protects against denial-of-service attacks via large payloads. The default limit is 1MB (1024 * 1024 bytes).
§Arguments
limit- Maximum body size in bytes
§Example
use rustapi_rs::prelude::*;
RustApi::new()
.body_limit(5 * 1024 * 1024) // 5MB limit
.route("/upload", post(upload_handler))
.run("127.0.0.1:8080")
.awaitSourcepub fn no_body_limit(self) -> Self
pub fn no_body_limit(self) -> Self
Sourcepub fn layer<L>(self, layer: L) -> Selfwhere
L: MiddlewareLayer,
pub fn layer<L>(self, layer: L) -> Selfwhere
L: MiddlewareLayer,
Add a middleware layer to the application
Layers are executed in the order they are added (outermost first). The first layer added will be the first to process the request and the last to process the response.
§Example
use rustapi_rs::prelude::*;
use rustapi_core::middleware::{RequestIdLayer, TracingLayer};
RustApi::new()
.layer(RequestIdLayer::new()) // First to process request
.layer(TracingLayer::new()) // Second to process request
.route("/", get(handler))
.run("127.0.0.1:8080")
.awaitSourcepub fn register_schema<T: for<'a> Schema<'a>>(self) -> Self
pub fn register_schema<T: for<'a> Schema<'a>>(self) -> Self
Sourcepub fn openapi_info(
self,
title: &str,
version: &str,
description: Option<&str>,
) -> Self
pub fn openapi_info( self, title: &str, version: &str, description: Option<&str>, ) -> Self
Configure OpenAPI info (title, version, description)
Sourcepub fn route(self, path: &str, method_router: MethodRouter) -> Self
pub fn route(self, path: &str, method_router: MethodRouter) -> Self
Sourcepub fn mount(self, path: &str, method_router: MethodRouter) -> Self
👎Deprecated: Use route() directly or mount_route() for macro-based routing
pub fn mount(self, path: &str, method_router: MethodRouter) -> Self
Mount a handler (convenience method)
Alias for .route(path, method_router) for a single handler.
Sourcepub fn mount_route(self, route: Route) -> Self
pub fn mount_route(self, route: Route) -> Self
Sourcepub fn docs(self, path: &str) -> Self
pub fn docs(self, path: &str) -> Self
Enable Swagger UI documentation
This adds two endpoints:
{path}- Swagger UI interface{path}/openapi.json- OpenAPI JSON specification
§Example
RustApi::new()
.route("/users", get(list_users))
.docs("/docs") // Swagger UI at /docs, spec at /docs/openapi.json
.run("127.0.0.1:8080")
.awaitSourcepub fn docs_with_info(
self,
path: &str,
title: &str,
version: &str,
description: Option<&str>,
) -> Self
pub fn docs_with_info( self, path: &str, title: &str, version: &str, description: Option<&str>, ) -> Self
Sourcepub fn docs_with_auth(self, path: &str, username: &str, password: &str) -> Self
pub fn docs_with_auth(self, path: &str, username: &str, password: &str) -> Self
Enable Swagger UI documentation with Basic Auth protection
When username and password are provided, the docs endpoint will require Basic Authentication. This is useful for protecting API documentation in production environments.
§Example
RustApi::new()
.route("/users", get(list_users))
.docs_with_auth("/docs", "admin", "secret123")
.run("127.0.0.1:8080")
.awaitSourcepub fn docs_with_auth_and_info(
self,
path: &str,
username: &str,
password: &str,
title: &str,
version: &str,
description: Option<&str>,
) -> Self
pub fn docs_with_auth_and_info( self, path: &str, username: &str, password: &str, title: &str, version: &str, description: Option<&str>, ) -> Self
Sourcepub fn into_router(self) -> Router
pub fn into_router(self) -> Router
Get the inner router (for testing or advanced usage)
Sourcepub fn layers(&self) -> &LayerStack
pub fn layers(&self) -> &LayerStack
Get the layer stack (for testing)