pub struct OcpiRouter { /* private fields */ }server only.Expand description
Builds the axum::Router that serves one OCPI version.
use std::sync::Arc;
use ocpi_kit::server::{InMemoryTokenStore, OcpiRouter};
use ocpi_kit::types::Url;
use ocpi_kit::VersionNumber;
let router = OcpiRouter::new(
VersionNumber::V2_3_0,
Url::new("https://cpo.example.com/ocpi/cpo/2.3.0")?,
Arc::new(InMemoryTokenStore::new()),
)
.credentials(credentials)
.locations_sender(locations)
.build();The version details endpoint is generated from exactly what was mounted, so a peer’s discovery can never disagree with what this server actually serves.
Implementations§
Source§impl OcpiRouter
impl OcpiRouter
Sourcepub fn new(
version: VersionNumber,
base_url: Url,
tokens: Arc<dyn TokenStore>,
) -> Self
pub fn new( version: VersionNumber, base_url: Url, tokens: Arc<dyn TokenStore>, ) -> Self
Starts a router for one OCPI version, published under base_url.
Sourcepub fn with_config(self, config: ServerConfig) -> Self
pub fn with_config(self, config: ServerConfig) -> Self
Overrides the server configuration.
Sourcepub fn credentials<H: CredentialsHandler>(self, handler: H) -> Self
pub fn credentials<H: CredentialsHandler>(self, handler: H) -> Self
Mounts the credentials module, which every implementation must serve.
Sourcepub fn locations_sender<H: LocationsSender>(self, handler: H) -> Self
pub fn locations_sender<H: LocationsSender>(self, handler: H) -> Self
Mounts the Locations Sender interface: GET on locations, EVSEs and connectors.
Sourcepub fn locations_receiver<H: LocationsReceiver>(self, handler: H) -> Self
pub fn locations_receiver<H: LocationsReceiver>(self, handler: H) -> Self
Mounts the Locations Receiver interface: the client-owned-object GET, PUT and PATCH.
Sourcepub fn tokens_sender<H: TokensSender>(self, handler: H) -> Self
pub fn tokens_sender<H: TokensSender>(self, handler: H) -> Self
Mounts the Tokens Sender interface: GET list and real-time authorization.
Sourcepub fn tokens_receiver<H: TokensReceiver>(self, handler: H) -> Self
pub fn tokens_receiver<H: TokensReceiver>(self, handler: H) -> Self
Mounts the Tokens Receiver interface.
Sourcepub fn cdrs_sender<H: CdrsSender>(self, handler: H) -> Self
pub fn cdrs_sender<H: CdrsSender>(self, handler: H) -> Self
Mounts the CDRs Sender interface.
Sourcepub fn cdrs_receiver<H: CdrsReceiver>(self, handler: H) -> Self
pub fn cdrs_receiver<H: CdrsReceiver>(self, handler: H) -> Self
Mounts the CDRs Receiver interface, including the POST that returns a Location header.
Sourcepub fn sessions_sender<H: SessionsSender>(self, handler: H) -> Self
pub fn sessions_sender<H: SessionsSender>(self, handler: H) -> Self
Mounts the Sessions Sender interface, including PUT charging_preferences.
Sourcepub fn sessions_receiver<H: SessionsReceiver>(self, handler: H) -> Self
pub fn sessions_receiver<H: SessionsReceiver>(self, handler: H) -> Self
Mounts the Sessions Receiver interface.
Sourcepub fn tariffs_sender<H: TariffsSender>(self, handler: H) -> Self
pub fn tariffs_sender<H: TariffsSender>(self, handler: H) -> Self
Mounts the Tariffs Sender interface.
Sourcepub fn tariffs_receiver<H: TariffsReceiver>(self, handler: H) -> Self
pub fn tariffs_receiver<H: TariffsReceiver>(self, handler: H) -> Self
Mounts the Tariffs Receiver interface, including the DELETE.
Sourcepub fn commands_receiver<H: CommandsReceiver>(self, handler: H) -> Self
pub fn commands_receiver<H: CommandsReceiver>(self, handler: H) -> Self
Mounts the Commands Receiver interface: POST {commands}/{command}.
Sourcepub fn hub_client_info_sender<H: HubClientInfoSender>(self, handler: H) -> Self
pub fn hub_client_info_sender<H: HubClientInfoSender>(self, handler: H) -> Self
Mounts the Hub Client Info Sender interface: GET {hubclientinfo}.
A configuration module, so its requests carry no routing headers.
Sourcepub fn hub_client_info_receiver<H: HubClientInfoReceiver>(
self,
handler: H,
) -> Self
pub fn hub_client_info_receiver<H: HubClientInfoReceiver>( self, handler: H, ) -> Self
Mounts the Hub Client Info Receiver interface: GET/PUT {hubclientinfo}/{cc}/{party}.
The party in the URL is the party the ClientInfo is about, not the party that owns
the object — a hub pushes information about every other party to each of its clients — so
the ownership rule that guards the other client-owned-object URLs deliberately does not
apply here.
Sourcepub fn commands_sender<H: CommandsSender>(self, handler: H) -> Self
pub fn commands_sender<H: CommandsSender>(self, handler: H) -> Self
Mounts the Commands Sender interface: the callback the Receiver POSTs its result to.
The path is {commands}/{command}/{unique_id}, which is the shape the specification’s own
example uses (.../commands/RESERVE_NOW/1234). Build the matching response_url with
CallbackUrls::command_result so the two can never drift apart.
This URL might contain a unique ID to be able to distinguish between StartSession requests.
Sourcepub fn charging_profiles_receiver<H: ChargingProfilesReceiver>(
self,
handler: H,
) -> Self
pub fn charging_profiles_receiver<H: ChargingProfilesReceiver>( self, handler: H, ) -> Self
Mounts the Charging Profiles Receiver interface: GET/PUT/DELETE on a session.
Sourcepub fn charging_profiles_sender<H: ChargingProfilesSender>(
self,
handler: H,
) -> Self
pub fn charging_profiles_sender<H: ChargingProfilesSender>( self, handler: H, ) -> Self
Mounts the Charging Profiles Sender interface: the three result callbacks and the
CPO-initiated PUT of a changed active profile.
See ChargingProfilesSender for why there are three callback paths rather than one, and
CallbackUrls for building the response_urls that reach them.
Sourcepub fn payments_sender<H: PaymentsSender>(self, handler: H) -> Self
pub fn payments_sender<H: PaymentsSender>(self, handler: H) -> Self
Mounts the Payments Sender interface: the terminals and financial advice this PTP owns.
Sourcepub fn payments_receiver<H: PaymentsReceiver>(self, handler: H) -> Self
pub fn payments_receiver<H: PaymentsReceiver>(self, handler: H) -> Self
Mounts the Payments Receiver interface: the CPO’s copy of the PTP’s objects.
Note the POST: unlike every other Receiver interface in OCPI these objects are created
with POST and their URLs carry no owning party.
Sourcepub fn build(self) -> Router
pub fn build(self) -> Router
Finishes the router.
The /versions and version-details endpoints are added automatically and describe exactly
what was mounted.
§Panics
Panics when the router publishes a version this build cannot translate the canonical model
into — today, anything other than 2.3.0 or 2.2.1. Handlers are written against
v2_3_0, so a router that advertised OCPI 2.1.1 would answer a partner
with objects in a shape that version does not have; better a message at start-up than an
invoice built from it.