Sample code for 30+ languages & platforms
Rust

HttpPostJson2 Example

See more HTTP Examples

Demonstrates use of the HttpPostJson2 method.

Chilkat Rust Downloads

Rust

// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code

// See PostJson2Async Example for the async equivalent of this example.

let http = chilkat::Http::new();

// Sends a POST equivalent to the following CURL command:

// curl -X POST https://sandbox.plaid.com/institutions/get \
//   -H 'content-type: application/json' \
//   -d '{
//     "client_id": String,
//     "secret":String,
//     "count": Number,
//     "offset": Number
//   }'

// Suppress some default headers that would automatically added..
http.set_accept_charset("");
http.set_user_agent("");
http.set_accept_language("");
http.set_allow_gzip(false);

let json_body = "{\"client_id\": \"PLAID_CLIENT_ID\", \"secret\":\"PLAID_SECRET\", \"count\": 10, \"offset\": 0}".to_string();
let Ok(resp) = http.post_json2("https://sandbox.plaid.com/institutions/get", "application/json", &json_body) else {
    println!("{}", http.last_error_text());
    return;
};

let status_code = resp.status_code();
println!("Response status code = {}", status_code);

// Examine the JSON response..
let json = chilkat::JsonObject::new();
let _ = json.load(&resp.body_str());
json.set_emit_compact(false);
println!("JSON Response Body:");
println!("{}", json.emit().unwrap_or_default());