pub struct Rest { /* private fields */ }
Implementations
sourceimpl Rest
impl Rest
pub fn auth(&self) -> Auth<'_>
pub fn channels(&self) -> Channels<'_>
pub fn options(&self) -> &ClientOptions
pub fn new(key: &str) -> Result<Self>
sourcepub fn stats(&self) -> PaginatedRequestBuilder<'_, Stats>
pub fn stats(&self) -> PaginatedRequestBuilder<'_, Stats>
Start building a GET request to /stats.
Returns a stats::RequestBuilder which is used to set parameters before sending the stats request.
Example
use ably::stats::Stats;
let client = ably::Rest::from("<api_key>");
let res = client
.stats()
.start("2021-09-09:15:00")
.end("2021-09-09:15:05")
.send()
.await?;
let stats = res.items().await?;
sourcepub async fn time(&self) -> Result<DateTime<Utc>>
pub async fn time(&self) -> Result<DateTime<Utc>>
Sends a GET request to /time and returns the server time in UTC.
Example
let client = ably::Rest::from("<api_key>");
let time = client.time().await?;
sourcepub fn request(&self, method: Method, path: &str) -> RequestBuilder<'_>
pub fn request(&self, method: Method, path: &str) -> RequestBuilder<'_>
Start building a HTTP request to the Ably REST API.
Returns a RequestBuilder which can be used to set query params, headers and the request body before sending the request.
Example
use ably::http::{HeaderMap,Method};
let client = ably::Rest::from("<api_key>");
let mut headers = HeaderMap::new();
headers.insert("Foo", "Bar".parse().unwrap());
let response = client
.request(Method::POST, "/some/custom/path")
.params(&[("key1", "val1"), ("key2", "val2")])
.body(r#"{"json":"body"}"#)
.headers(headers)
.send()
.await?;
Errors
Returns an error if sending the request fails or if the resulting response is unsuccessful (i.e. the status code is not in the 200-299 range).
sourcepub fn paginated_request_with_options<'a, T: Decode + 'a>(
&'a self,
method: Method,
path: &str,
options: T::Options
) -> PaginatedRequestBuilder<'_, T>
pub fn paginated_request_with_options<'a, T: Decode + 'a>(
&'a self,
method: Method,
path: &str,
options: T::Options
) -> PaginatedRequestBuilder<'_, T>
Start building a paginated HTTP request to the Ably REST API.
Returns a PaginatedRequestBuilder which can be used to set query params before sending the request.
Example
use futures::TryStreamExt;
use ably::http::Method;
let client = ably::Rest::from("<api_key>");
let mut pages = client
.paginated_request::<String>(Method::GET, "/time")
.forwards()
.limit(1)
.pages();
let page = pages.try_next().await?.expect("Expected a page");
let items = page.items().await?;
assert_eq!(items.len(), 1);
Errors
Returns an error if sending the request fails or if the resulting response is unsuccessful (i.e. the status code is not in the 200-299 range).
pub fn paginated_request<'a, T: DeserializeOwned + Send + 'static>(
&'a self,
method: Method,
path: &str
) -> PaginatedRequestBuilder<'_, DecodeRaw<T>>
Trait Implementations
sourceimpl From<&str> for Rest
impl From<&str> for Rest
sourcefn from(s: &str) -> Self
fn from(s: &str) -> Self
Returns a Rest client initialised with an API key or token contained in the given string.
Example
// Initialise a Rest client with an API key.
let client = ably::Rest::from("<api_key>");
// Initialise a Rest client with a token.
let client = ably::Rest::from("<token>");