pub struct TmfClient { /* private fields */ }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
impl TmfClient
Sourcepub fn new(
base_url: impl Into<String>,
transport: impl Transport + 'static,
) -> Result<Self>
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.
Sourcepub async fn get<T: DeserializeOwned>(
&self,
path: &str,
id: &str,
query: &Query,
) -> Result<T>
pub async fn get<T: DeserializeOwned>( &self, path: &str, id: &str, query: &Query, ) -> Result<T>
GET {path}/{id} returning a single resource.
Sourcepub async fn get_absolute<T: DeserializeOwned>(
&self,
url: &str,
query: &Query,
) -> Result<T>
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.
Sourcepub async fn get_cross_origin<T: DeserializeOwned>(
&self,
url: &str,
query: &Query,
) -> Result<T>
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.
Sourcepub fn require_same_origin(&self, url: &str) -> Result<()>
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.
Sourcepub async fn list<T: DeserializeOwned>(
&self,
path: &str,
query: &Query,
) -> Result<Page<T>>
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.
Sourcepub async fn list_absolute<T: DeserializeOwned>(
&self,
url: &str,
) -> Result<Page<T>>
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.
Sourcepub async fn create<B: Serialize, T: DeserializeOwned>(
&self,
path: &str,
body: &B,
) -> Result<T>
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.
Sourcepub async fn patch<'a, U: PatchBody + 'a, T: DeserializeOwned>(
&self,
path: &str,
id: &str,
body: impl Into<Patch<'a, U>>,
) -> Result<T>
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.
Sourcepub async fn delete(&self, path: &str, id: &str) -> Result<()>
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.
Sourcepub async fn send(&self, request: TmfRequest) -> Result<TmfResponse>
pub async fn send(&self, request: TmfRequest) -> Result<TmfResponse>
Executes a request, applying TMF error handling to the response.
Source§impl TmfClient
impl TmfClient
Sourcepub async fn get_tagged<T: DeserializeOwned>(
&self,
path: &str,
id: &str,
query: &Query,
) -> Result<Tagged<T>>
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.
Sourcepub 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>
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.
Sourcepub async fn delete_if_match(
&self,
path: &str,
id: &str,
etag: &EntityTag,
) -> Result<()>
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 Conditional for TmfClient
impl Conditional for TmfClient
Source§async fn fetch<T>(&self, id: &str, query: &Query) -> Result<Tagged<T>>where
T: Resolvable<Output = T> + DeserializeOwned,
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