pub trait Requestable {
    // Required method
    fn request<'life0, 'async_trait, Resp>(
        &'life0 self,
        method: Method,
        data: Option<Value>
    ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>
       where Resp: for<'a> Deserialize<'a> + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn request_generic<'life0, 'async_trait, T>(
        &'life0 self,
        method: Method
    ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
       where T: Serialize + DeserializeOwned + Debug + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn set<'life0, 'life1, 'async_trait, T, Resp>(
        &'life0 self,
        data: &'life1 T
    ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>
       where T: Serialize + DeserializeOwned + Debug + Send + Sync + 'async_trait,
             Resp: for<'a> Deserialize<'a> + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn get_as_string<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<Response<String>>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn get<'life0, 'async_trait, T>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
       where T: Serialize + DeserializeOwned + Debug + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn delete<'life0, 'async_trait, Resp>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>
       where Resp: for<'a> Deserialize<'a> + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn update<'life0, 'life1, 'async_trait, T, Resp>(
        &'life0 self,
        data: &'life1 T
    ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>
       where T: DeserializeOwned + Serialize + Debug + Send + Sync + 'async_trait,
             Resp: for<'a> Deserialize<'a> + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

An async trait for making HTTP requests and deserializing responses.

Required Methods§

source

fn request<'life0, 'async_trait, Resp>( &'life0 self, method: Method, data: Option<Value> ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>where Resp: for<'a> Deserialize<'a> + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Sends an HTTP request with a given HTTP method and data and returns a deserialized response.

Arguments
  • method - An HTTP method (http::Method) for the request.
  • data - An optional JSON value (serde_json::Value) to include in the request body.
Generic type parameters
  • Resp - A type that implements the Deserialize trait and represents the response body.
Returns

A Result containing a deserialized http::Response on success or an error on failure.

Provided Methods§

source

fn request_generic<'life0, 'async_trait, T>( &'life0 self, method: Method ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>where T: Serialize + DeserializeOwned + Debug + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait,

Sends an HTTP request with a given HTTP method and returns a generic deserialized response.

This method is a convenience wrapper around request() that doesn’t require a request body and returns a generic deserialized response.

Generic type parameters
  • T - A type that implements both the Serialize and DeserializeOwned traits and represents the response body.
Arguments
  • method - An HTTP method (http::Method) for the request.
Returns

A Result containing a generic deserialized response on success or an error on failure.

source

fn set<'life0, 'life1, 'async_trait, T, Resp>( &'life0 self, data: &'life1 T ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>where T: Serialize + DeserializeOwned + Debug + Send + Sync + 'async_trait, Resp: for<'a> Deserialize<'a> + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

use firebase_rs::{Firebase, Response, Requestable};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct User {
   name: String
}

let user = User { name: String::default() };
let mut firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
let endpoint = firebase.at("users");
let users = endpoint.set::<_, String>(&user).await;
source

fn get_as_string<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Response<String>>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

use firebase_rs::{Firebase, Requestable};

let mut firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
let endpoint = firebase.at("users");
let users = endpoint.get_as_string().await;
source

fn get<'life0, 'async_trait, T>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>where T: Serialize + DeserializeOwned + Debug + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait,

use std::collections::HashMap;
use firebase_rs::{Firebase, Requestable};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct User {
    name: String
}

let mut firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
let endpoint = firebase.at("users").at("USER_ID");
let user = endpoint.get::<User>().await;

 // OR

let mut firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
let endpoint = firebase.at("users");
let user = endpoint.get::<HashMap<String, User>>().await;
source

fn delete<'life0, 'async_trait, Resp>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>where Resp: for<'a> Deserialize<'a> + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait,

use firebase_rs::{Firebase, Response, Result, Requestable};

let mut firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
let endpoint = firebase.at("users").at("USER_ID");
endpoint.delete::<serde_json::Value>().await;
source

fn update<'life0, 'life1, 'async_trait, T, Resp>( &'life0 self, data: &'life1 T ) -> Pin<Box<dyn Future<Output = Result<Response<Resp>>> + Send + 'async_trait>>where T: DeserializeOwned + Serialize + Debug + Send + Sync + 'async_trait, Resp: for<'a> Deserialize<'a> + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

use firebase_rs::{Firebase, Response, Requestable};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct User {
    name: String
}

let user = User { name: String::default() };
let mut firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
let endpoint = firebase.at("users").at("USER_ID");
let users: Response<serde_json::Value> = endpoint.update(&user).await.unwrap();

Implementors§