pub struct WebwareClient<State = Unregistered> { /* private fields */ }
Expand description
The web client to consume SoftENGINE’s WEBSERVICES
Implementations§
Source§impl WebwareClient
impl WebwareClient
Sourcepub async fn register(self) -> WWClientResult<WebwareClient<Registered>>
pub async fn register(self) -> WWClientResult<WebwareClient<Registered>>
Sends a REGISTER
request to the WEBWARE instance and returns a registered client
or an error
Sourcepub async fn with_registered<F, T>(self, f: F) -> WWClientResult<T>
pub async fn with_registered<F, T>(self, f: F) -> WWClientResult<T>
Provides a harness for operating with the client by registering, running the provided closure and then deregistering the client.
§Example
use wwsvc_rs::futures::FutureExt;
#[tokio::main]
async fn main() {
let client = wwsvc_rs::WebwareClient::builder()
.webware_url("https://meine-webware.de")
.vendor_hash("my-vendor-hash")
.app_hash("my-app-hash")
.secret("1")
.revision(1)
.build();
let article_result = client
.with_registered(|registered_client| async {
// Do something with the registered client
}.boxed())
.await;
}
Source§impl<State: Ready> WebwareClient<State>
impl<State: Ready> WebwareClient<State>
Sourcepub fn create_cursor(self, max_lines: u32) -> WebwareClient<OpenCursor>
pub fn create_cursor(self, max_lines: u32) -> WebwareClient<OpenCursor>
Creates a new pagination cursor and makes it available for the next requests (until it is closed)
Sourcepub fn credentials(&self) -> &Credentials
pub fn credentials(&self) -> &Credentials
Generates a set of credentials from the current client.
Sourcepub fn set_result_max_lines(&mut self, max_lines: u32)
pub fn set_result_max_lines(&mut self, max_lines: u32)
Sets the maximum amount of results that are returned in a response
Sourcepub fn get_default_headers(
&mut self,
additional_headers: Option<HashMap<&str, &str>>,
) -> WWClientResult<HeaderMap>
pub fn get_default_headers( &mut self, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<HeaderMap>
Returns a set of headers, that are required on all requests to the WEBSERVICES (except REGISTER
).
This will automatically append necessary authentication headers and increase the request ID, if register()
was successful.
Sourcepub fn get_bin_headers(
&mut self,
additional_headers: Option<HashMap<&str, &str>>,
) -> WWClientResult<HeaderMap>
pub fn get_bin_headers( &mut self, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<HeaderMap>
Returns the same set of headers, that get_default_headers()
returns, except the result type header is set to BIN
instead.
Sourcepub async fn deregister(self) -> WWClientResult<WebwareClient<Unregistered>>
pub async fn deregister(self) -> WWClientResult<WebwareClient<Unregistered>>
Sends a DEREGISTER
request to the WEBWARE instance, in order to invalidate the service pass.
Sourcepub fn prepare_request(
&mut self,
method: Method,
function: &str,
version: u32,
parameters: HashMap<&str, &str>,
additional_headers: Option<HashMap<&str, &str>>,
) -> WWClientResult<Request>
pub fn prepare_request( &mut self, method: Method, function: &str, version: u32, parameters: HashMap<&str, &str>, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<Request>
Prepares a request to the WEBSERVICES.
This will return a [reqwest::Request]
object, that can be executed using the execute_request
method.
NOTE: This method will also update the internal state of the client, such as the request ID and cursor.
Sourcepub async fn execute_request(
&mut self,
request: Request,
) -> WWClientResult<Response>
pub async fn execute_request( &mut self, request: Request, ) -> WWClientResult<Response>
Executes a prepared request to the WEBSERVICES.
This will execute the prepared request and return a response object.
NOTE: This method will also update the internal state of the client, such as the request ID and cursor.
Sourcepub async fn request(
&mut self,
method: Method,
function: &str,
version: u32,
parameters: HashMap<&str, &str>,
additional_headers: Option<HashMap<&str, &str>>,
) -> WWClientResult<Value>
pub async fn request( &mut self, method: Method, function: &str, version: u32, parameters: HashMap<&str, &str>, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<Value>
Performs a request to the WEBSERVICES and returns a JSON value.
Sourcepub async fn request_as_response(
&mut self,
method: Method,
function: &str,
version: u32,
parameters: HashMap<&str, &str>,
additional_headers: Option<HashMap<&str, &str>>,
) -> WWClientResult<Response>
pub async fn request_as_response( &mut self, method: Method, function: &str, version: u32, parameters: HashMap<&str, &str>, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<Response>
Performs a request to the WEBSERVICES and returns a response object.
Sourcepub async fn request_generic<T>(
&mut self,
method: Method,
function: &str,
version: u32,
parameters: HashMap<&str, &str>,
additional_headers: Option<HashMap<&str, &str>>,
) -> WWClientResult<T>where
T: DeserializeOwned,
pub async fn request_generic<T>(
&mut self,
method: Method,
function: &str,
version: u32,
parameters: HashMap<&str, &str>,
additional_headers: Option<HashMap<&str, &str>>,
) -> WWClientResult<T>where
T: DeserializeOwned,
Performs a request to the WEBSERVICES and deserializes the response to the type T
.
NOTE: Due to the nature of the WEBSERVICES, deserialization might fail due to structural issues. In that case, use request()
instead.
Source§impl WebwareClient<OpenCursor>
impl WebwareClient<OpenCursor>
Sourcepub fn suspend_cursor(&mut self)
pub fn suspend_cursor(&mut self)
Suspends the cursor, so that it is not used for the next request
Sourcepub fn resume_cursor(&mut self)
pub fn resume_cursor(&mut self)
Resumes the cursor, so that it is used for the next request
Sourcepub fn cursor_closed(&self) -> bool
pub fn cursor_closed(&self) -> bool
Returns whether the current cursor is closed.
Returns None, if no cursor is available.
Trait Implementations§
Source§impl<State: Clone> Clone for WebwareClient<State>
impl<State: Clone> Clone for WebwareClient<State>
Source§fn clone(&self) -> WebwareClient<State>
fn clone(&self) -> WebwareClient<State>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more