Skip to main content

TmfClient

Struct TmfClient 

Source
pub struct TmfClient { /* private fields */ }
Available on crate feature api only.
Expand description

A configured TM Forum API endpoint.

Wraps a Transport with a base URL and the request/response handling that TMF630 prescribes: content negotiation, error-body parsing and pagination headers. Per-API clients such as ProductCatalogClient delegate to this.

Implementations§

Source§

impl TmfClient

Source

pub fn new( base_url: impl Into<String>, transport: impl Transport + 'static, ) -> Result<Self>

Creates a client for base_url, dispatching through transport.

The base URL should include the API root, e.g. https://host/tmf-api/productCatalogManagement/v5.

§Errors

Returns Error::InvalidBaseUrl if the URL is empty.

Source

pub fn base_url(&self) -> &str

The configured base URL, without a trailing slash.

Source

pub fn url(&self, path: &str) -> String

Resolves a resource path against the base URL.

Source

pub async fn get<T: DeserializeOwned>( &self, path: &str, id: &str, query: &Query, ) -> Result<T>

GET {path}/{id} returning a single resource.

Source

pub async fn get_absolute<T: DeserializeOwned>( &self, url: &str, query: &Query, ) -> Result<T>

GET an absolute URL on this API’s own origin, returning a resource.

Used to follow an href that names a different API than this client is configured for — the catalog referring to party management, say. In a TM Forum deployment those sit at different paths on one host (/tmf-api/productCatalogManagement/v5 beside /tmf-api/partyManagement/v5), which is why the common case needs no escape hatch.

§Errors

Returns Error::CrossOrigin if the URL leaves this client’s origin. An href is server-controlled and the transport attaches credentials to whatever URL it is handed, so following one to another host would hand a bearer token to whoever owns that host. Genuine federation across origins goes through get_cross_origin, where leaving the origin is the point and saying so is the caller’s decision.

Source

pub async fn get_cross_origin<T: DeserializeOwned>( &self, url: &str, query: &Query, ) -> Result<T>

GET an absolute URL on any origin, returning a resource.

The unguarded counterpart of get_absolute, for a deployment that really does federate across hosts.

The transport applies this client’s credentials to the URL it is given, so calling this with a URL that came from a payload sends your token wherever that payload said. Use it with a URL you chose, or with one from a server you trust to name only hosts you would authenticate against.

Source

pub fn require_same_origin(&self, url: &str) -> Result<()>

Refuses a server-supplied URL that leaves this client’s origin.

§Errors

Returns Error::CrossOrigin when the origins differ, or when either URL cannot be read confidently — see same_origin.

Source

pub async fn list<T: DeserializeOwned>( &self, path: &str, query: &Query, ) -> Result<Page<T>>

GET {path} returning one page of resources plus what the server said about the rest.

Source

pub async fn list_absolute<T: DeserializeOwned>( &self, url: &str, ) -> Result<Page<T>>

GET an absolute URL returning one page of resources.

Used to follow a Link: …; rel="next" header, whose target is the server’s own and may carry a cursor rather than an offset.

§Errors

Returns Error::CrossOrigin if the URL is not on the same origin as this client’s base. A Link header is server-controlled and the transport attaches credentials to whatever it is given, so a next-page link that leaves the API is refused rather than followed.

Source

pub async fn create<B: Serialize, T: DeserializeOwned>( &self, path: &str, body: &B, ) -> Result<T>

POST {path} creating a resource.

§Errors

Returns Error::Accepted when the server answers 202 — it took the request but has not created anything yet.

Source

pub async fn patch<'a, U: PatchBody + 'a, T: DeserializeOwned>( &self, path: &str, id: &str, body: impl Into<Patch<'a, U>>, ) -> Result<T>

PATCH {path}/{id} updating a resource.

Patch carries the body and the semantics together, so the Content-Type always describes what is actually being sent.

§Errors

Returns Error::Accepted when the server answers 202 — it took the request but has not applied it yet.

Source

pub async fn delete(&self, path: &str, id: &str) -> Result<()>

DELETE {path}/{id}.

Succeeds on 204 No Content and on 202 Accepted, which conformant servers return when the deletion is asynchronous. Unlike a create or a patch, a delete has no resource to hand back either way, so the two are not worth distinguishing here.

Source

pub async fn send(&self, request: TmfRequest) -> Result<TmfResponse>

Executes a request, applying TMF error handling to the response.

Source§

impl TmfClient

Source

pub async fn get_tagged<T: DeserializeOwned>( &self, path: &str, id: &str, query: &Query, ) -> Result<Tagged<T>>

GET {path}/{id} returning the resource and its entity-tag.

The path-taking form of Conditional::fetch, for a collection whose resource type this crate does not model.

Source

pub async fn patch_if_match<'a, U: PatchBody + 'a, T: DeserializeOwned>( &self, path: &str, id: &str, body: impl Into<Patch<'a, U>>, etag: &EntityTag, ) -> Result<T>

PATCH {path}/{id}, but only while the resource still carries etag.

The path-taking form of Tagged::update.

Source

pub async fn delete_if_match( &self, path: &str, id: &str, etag: &EntityTag, ) -> Result<()>

DELETE {path}/{id}, but only while the resource still carries etag.

The path-taking form of Tagged::remove.

Trait Implementations§

Source§

impl Clone for TmfClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Conditional for TmfClient

Source§

async fn fetch<T>(&self, id: &str, query: &Query) -> Result<Tagged<T>>
where T: Resolvable<Output = T> + DeserializeOwned,

GETs one resource together with its entity-tag. Read more
Source§

async fn fetch_if_changed<T>( &self, id: &str, query: &Query, held: Option<&EntityTag>, ) -> Result<Option<Tagged<T>>>
where T: Resolvable<Output = T> + DeserializeOwned,

GETs one resource, unless it still carries held. Read more
Source§

impl Debug for TmfClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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, !>

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