pub trait RoutableHttpEvent:
Send
+ Sync
+ Clone
+ 'static {
Show 13 methods
// Required methods
fn path(&self) -> Option<String>;
fn http_method(&self) -> String;
// Provided methods
fn route(&self) -> Option<String> { ... }
fn path_parameters(&self) -> Option<&HashMap<String, String>> { ... }
fn url_query(&self) -> Option<String> { ... }
fn client_address(&self) -> Option<String> { ... }
fn http_headers(&self) -> Option<&HeaderMap> { ... }
fn response_headers(&self) -> Option<&HeaderMap> { ... }
fn user_agent(&self) -> Option<String> { ... }
fn url_scheme(&self) -> String { ... }
fn server_address(&self) -> Option<String> { ... }
fn server_port(&self) -> Option<u16> { ... }
fn set_otel_http_attributes(
&self,
span: &Span,
route_pattern: &str,
lambda_context: &Context,
) { ... }
}
Expand description
A trait for HTTP events that can be routed by the router.
This trait defines the minimum requirements for an HTTP event to be usable with the routing system, as well as OpenTelemetry semantic conventions for HTTP spans. Any event type that implements this trait can be used with the router and will automatically get standardized span attributes.
§Examples
use lambda_lw_http_router_core::RoutableHttpEvent;
use http::HeaderMap;
#[derive(Clone)] // Required by RoutableHttpEvent
struct CustomHttpEvent {
path: String,
method: String,
headers: HeaderMap,
}
impl RoutableHttpEvent for CustomHttpEvent {
fn path(&self) -> Option<String> {
Some(self.path.clone())
}
fn http_method(&self) -> String {
self.method.clone()
}
fn http_headers(&self) -> Option<&HeaderMap> {
Some(&self.headers)
}
}
Required Methods§
Sourcefn http_method(&self) -> String
fn http_method(&self) -> String
Returns the HTTP method of the request
Provided Methods§
Sourcefn route(&self) -> Option<String>
fn route(&self) -> Option<String>
Returns the API Gateway resource pattern if available, otherwise None
Sourcefn path_parameters(&self) -> Option<&HashMap<String, String>>
fn path_parameters(&self) -> Option<&HashMap<String, String>>
Returns pre-parsed path parameters if available
Sourcefn client_address(&self) -> Option<String>
fn client_address(&self) -> Option<String>
Returns the client IP address
Sourcefn http_headers(&self) -> Option<&HeaderMap>
fn http_headers(&self) -> Option<&HeaderMap>
Returns the request headers
Sourcefn response_headers(&self) -> Option<&HeaderMap>
fn response_headers(&self) -> Option<&HeaderMap>
Returns the response headers
Sourcefn user_agent(&self) -> Option<String>
fn user_agent(&self) -> Option<String>
Returns the user agent string
Sourcefn url_scheme(&self) -> String
fn url_scheme(&self) -> String
Returns the request scheme (http/https)
Sourcefn server_address(&self) -> Option<String>
fn server_address(&self) -> Option<String>
Returns the server address
fn server_port(&self) -> Option<u16>
Sourcefn set_otel_http_attributes(
&self,
span: &Span,
route_pattern: &str,
lambda_context: &Context,
)
fn set_otel_http_attributes( &self, span: &Span, route_pattern: &str, lambda_context: &Context, )
Sets OpenTelemetry semantic convention attributes on the current span
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.