[−][src]Crate heroku_rs
heroku_rs
The heroku_rs
crate provides convenient Rust bindings for the Heroku V3 API.
The heroku_rs HttpApiClient
is blocking by deafult.
Additional examples:
Creating the Heroku HttpApiClient
The heroku client is build on top of reqwest
library.
Creating the Heroku client only takes 1 line. This client has the default 30s http timeout and points to the production Heroku API.
If you wish to custumize the http timeout or the base endpoint. See the Example 2
Example 1 - Creating a simple client
use heroku_rs::framework::{apiclient::HerokuApiClient, HttpApiClient}; fn main() -> Result<(), Box<dyn std::error::Error>> { let api_client = HttpApiClient::create("API_KEY")?; // You can start making requests here Ok(()) }
In order to have a fully functional custom client you need to specify three things. Credentials, HttpApiClientConfig and ApiEnvironment
Example 2 - Creating a custom client
use heroku_rs::framework::{ auth::Credentials, apiclient::HerokuApiClient, ApiEnvironment, HttpApiClient, HttpApiClientConfig, }; use heroku_rs::endpoints::apps; fn main() -> Result<(), Box<dyn std::error::Error>> { let api_client = HttpApiClient::create("API_KEY")?; let response = api_client.request(&apps::AppList {}); match response { Ok(success) => println!("Success: {:#?}", success), Err(e) => println!("Error: {}", e), } Ok(()) }
Making a GET request to Heroku.
This request returns a vector of app
s, if successful.
use heroku_rs::framework::{apiclient::HerokuApiClient, HttpApiClient}; use heroku_rs::endpoints::apps; let api_client = HttpApiClient::create("API_KEY")?; let response = api_client.request(&apps::AppList {}); match response { Ok(success) => println!("Success: {:#?}", success), Err(e) => println!("Error: {}", e), }
Making POST requests to Heroku.
Some POST requests do not need body paramers at all.
This crate provides convinient parameter structs to inform you which endpoints take what parameters and which parameters are optional.
If you can see the params
parameter in this example, it takes three fields, all three are optional, matched from the Heroku documentation.
use heroku_rs::framework::{apiclient::HerokuApiClient, HttpApiClient}; use heroku_rs::endpoints::apps; let api_client = HttpApiClient::create("API_KEY")?; let app_name = String::from("FOO"); let response = api_client.request(&apps::AppCreate { // This will create an app with the name name `FOO_APP` params: apps::AppCreateParams { name: Some(app_name), region: None, stack: None, }, }); match response { Ok(success) => println!("Success: {:#?}", success), Err(e) => println!("Error: {}", e), }
Making DELETE requests to Heroku.
Contraty to POST requests, DELETE requests do not need body parameters at all.
Some DELETE requests return a body on the response if successful, some do not.
use heroku_rs::framework::{apiclient::HerokuApiClient, HttpApiClient}; use heroku_rs::endpoints::apps; let api_client = HttpApiClient::create("API_KEY")?; let app_id = String::from("FOO"); // This will delete the `FOO` app. let response = api_client.request(&apps::AppDelete { app_id }); match response { Ok(success) => println!("Success: {:#?}", success), Err(e) => println!("Error: {}", e), }
Making PATCH requests to Heroku.
Similar to POST requests, Some PATCH requests do not need body paramers.
use heroku_rs::framework::{apiclient::HerokuApiClient, HttpApiClient}; use heroku_rs::endpoints::apps; let api_client = HttpApiClient::create("API_KEY")?; let app_id = String::from("FOO"); // This will enable maintenance for the "FOO" app. let response = api_client.request(&apps::AppUpdate { app_id, params: apps::AppUpdateParams { build_stack: None, maintenance: Some(true), name: None, }, }); match response { Ok(success) => println!("Success: {:#?}", success), Err(e) => println!("Error: {}", e), }
Modules
endpoints | Module for the available endpoints on the crate. |
framework | Module for for authentication, api clients and response parsing. |