Skip to main content

embacle_server/
router.rs

1// ABOUTME: Axum router wiring all REST endpoints for the OpenAI-compatible API
2// ABOUTME: Mounts completions, models, and health routes with optional auth middleware
3//
4// SPDX-License-Identifier: Apache-2.0
5// Copyright (c) 2026 dravr.ai
6
7use axum::middleware;
8use axum::routing::{get, post};
9use axum::Router;
10
11use crate::auth;
12use crate::completions;
13use crate::health;
14use crate::models;
15use crate::state::SharedState;
16
17/// Build the application router with all endpoints
18///
19/// Routes:
20/// - `POST /v1/chat/completions` — Chat completion (streaming and non-streaming)
21/// - `GET /v1/models` — List available models
22/// - `GET /health` — Provider health check
23///
24/// The auth middleware is applied to all routes. It only enforces
25/// authentication when `EMBACLE_API_KEY` is set.
26pub fn build(state: SharedState) -> Router {
27    Router::new()
28        .route("/v1/chat/completions", post(completions::handle))
29        .route("/v1/models", get(models::handle))
30        .route("/health", get(health::handle))
31        .layer(middleware::from_fn(auth::require_auth))
32        .with_state(state)
33}