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::{PathDiscovery, UnderlayDiscovery};
26//! use tokio::net::TcpListener;
27//!
28//! struct MyUnderlayService;
29//! impl UnderlayDiscovery for MyUnderlayService {
30//!     fn list_underlays(
31//!         &self,
32//!         request_as: scion_proto::address::IsdAsn,
33//!     ) -> endhost_api_models::underlays::Underlays {
34//!         todo!();
35//!     }
36//! }
37//!
38//! struct MyPathService;
39//! #[async_trait::async_trait]
40//! impl PathDiscovery for MyPathService {
41//!     async fn list_segments(
42//!         &self,
43//!         request_as: scion_proto::address::IsdAsn,
44//!         dst: scion_proto::address::IsdAsn,
45//!         page_size: i32,
46//!         page_token: String,
47//!     ) -> Result<scion_proto::path::segment::Segments, scion_proto::path::SegmentsError>
48//!     {
49//!         todo!();
50//!     }
51//! }
52//!
53//! # async {
54//! let base_router = axum::Router::<()>::new();
55//! let router = nest_endhost_api(
56//!     base_router,
57//!     Arc::new(MyUnderlayService),
58//!     Arc::new(MyPathService),
59//! );
60//!
61//! let listener = TcpListener::bind(SocketAddr::from(([127, 0, 0, 1], 0)))
62//!     .await
63//!     .unwrap();
64//! axum::serve(listener, router.into_make_service())
65//!     .await
66//!     .unwrap();
67//! # };
68//! ```
69
70pub mod routes;