Skip to main content

OcpiRouter

Struct OcpiRouter 

Source
pub struct OcpiRouter { /* private fields */ }
Available on crate feature 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

Source

pub fn new( version: VersionNumber, base_url: Url, tokens: Arc<dyn TokenStore>, ) -> Self

Starts a router for one OCPI version, published under base_url.

Source

pub fn with_config(self, config: ServerConfig) -> Self

Overrides the server configuration.

Source

pub fn credentials<H: CredentialsHandler>(self, handler: H) -> Self

Mounts the credentials module, which every implementation must serve.

Source

pub fn locations_sender<H: LocationsSender>(self, handler: H) -> Self

Mounts the Locations Sender interface: GET on locations, EVSEs and connectors.

Source

pub fn locations_receiver<H: LocationsReceiver>(self, handler: H) -> Self

Mounts the Locations Receiver interface: the client-owned-object GET, PUT and PATCH.

Source

pub fn tokens_sender<H: TokensSender>(self, handler: H) -> Self

Mounts the Tokens Sender interface: GET list and real-time authorization.

Source

pub fn tokens_receiver<H: TokensReceiver>(self, handler: H) -> Self

Mounts the Tokens Receiver interface.

Source

pub fn cdrs_sender<H: CdrsSender>(self, handler: H) -> Self

Mounts the CDRs Sender interface.

Source

pub fn cdrs_receiver<H: CdrsReceiver>(self, handler: H) -> Self

Mounts the CDRs Receiver interface, including the POST that returns a Location header.

Source

pub fn sessions_sender<H: SessionsSender>(self, handler: H) -> Self

Mounts the Sessions Sender interface, including PUT charging_preferences.

Source

pub fn sessions_receiver<H: SessionsReceiver>(self, handler: H) -> Self

Mounts the Sessions Receiver interface.

Source

pub fn tariffs_sender<H: TariffsSender>(self, handler: H) -> Self

Mounts the Tariffs Sender interface.

Source

pub fn tariffs_receiver<H: TariffsReceiver>(self, handler: H) -> Self

Mounts the Tariffs Receiver interface, including the DELETE.

Source

pub fn commands_receiver<H: CommandsReceiver>(self, handler: H) -> Self

Mounts the Commands Receiver interface: POST {commands}/{command}.

Source

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.

Source

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.

Source

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.

Source

pub fn charging_profiles_receiver<H: ChargingProfilesReceiver>( self, handler: H, ) -> Self

Mounts the Charging Profiles Receiver interface: GET/PUT/DELETE on a session.

Source

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.

Source

pub fn payments_sender<H: PaymentsSender>(self, handler: H) -> Self

Mounts the Payments Sender interface: the terminals and financial advice this PTP owns.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more