use super::error::EndpointError;
use super::managed::ManagedResponse;
use super::surface::{RouteKind, RoutePolicy, SurfacePolicy};
use super::types::{HttpMethod, Request};
use async_trait::async_trait;
#[derive(Debug, Clone)]
pub struct ManagedRouteInfo {
pub kind: RouteKind,
pub surface_policy: Option<SurfacePolicy>,
pub route_policy: RoutePolicy,
}
#[async_trait]
pub trait HttpEndpoint: Send + Sync {
fn path(&self) -> &str;
fn methods(&self) -> &[HttpMethod];
async fn handle(&self, request: Request) -> Result<ManagedResponse, EndpointError>;
fn metadata(&self) -> Option<EndpointMetadata> {
None
}
fn managed_route(&self) -> Option<ManagedRouteInfo> {
None
}
}
#[derive(Debug, Clone)]
pub struct EndpointMetadata {
pub name: String,
pub description: Option<String>,
pub version: Option<String>,
pub tags: Vec<String>,
}
impl EndpointMetadata {
pub fn new(name: String) -> Self {
Self {
name,
description: None,
version: None,
tags: Vec::new(),
}
}
pub fn with_description(mut self, description: String) -> Self {
self.description = Some(description);
self
}
pub fn with_version(mut self, version: String) -> Self {
self.version = Some(version);
self
}
pub fn with_tags(mut self, tags: Vec<String>) -> Self {
self.tags = tags;
self
}
}