Skip to main content

endhost_api/
lib.rs

1// Copyright 2025 Anapaya Systems
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//   http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//! # SCION Endhost API
15//!
16//! Connect RPC API endpoint handlers and utilities to embed the endhost API into an existing
17//! [`axum::Router`].
18//!
19//! ## Basic Usage
20//!
21//! ```no_run
22//! use std::{net::SocketAddr, sync::Arc};
23//!
24//! use endhost_api::routes::nest_endhost_api;
25//! use endhost_api_models::{SegmentsDiscovery, UnderlayDiscovery};
26//! use tokio::net::TcpListener;
27//!
28//! struct MyUnderlayService;
29//! impl UnderlayDiscovery for MyUnderlayService {
30//!     fn list_underlays(
31//!         &self,
32//!         request_as: sciparse::identifier::isd_asn::IsdAsn,
33//!     ) -> endhost_api_models::underlays::Underlays {
34//!         todo!();
35//!     }
36//! }
37//!
38//! struct MySegmentsService;
39//! #[async_trait::async_trait]
40//! impl SegmentsDiscovery for MySegmentsService {
41//!     async fn list_segments(
42//!         &self,
43//!         request_as: sciparse::identifier::isd_asn::IsdAsn,
44//!         dst: sciparse::identifier::isd_asn::IsdAsn,
45//!         page_size: i32,
46//!         page_token: String,
47//!     ) -> Result<sciparse::segment::SegmentsPage, endhost_api_models::SegmentsError> {
48//!         todo!();
49//!     }
50//! }
51//!
52//! # async {
53//! let base_router = axum::Router::<()>::new();
54//! let router = nest_endhost_api(
55//!     base_router,
56//!     Arc::new(MyUnderlayService),
57//!     Arc::new(MySegmentsService),
58//! );
59//!
60//! let listener = TcpListener::bind(SocketAddr::from(([127, 0, 0, 1], 0)))
61//!     .await
62//!     .unwrap();
63//! axum::serve(listener, router.into_make_service())
64//!     .await
65//!     .unwrap();
66//! # };
67//! ```
68
69pub mod routes;