pub struct Request {
pub url: String,
pub method: Method,
pub headers: HashMap<String, String>,
pub body: Option<Value>,
}Expand description
One outbound request.
Every field has a default — GET, no headers, no body — so a literal names
the ones it sets and closes with ..Request::default().
use simpleplatform_sdk::http::{self, Method};
#[derive(Deserialize)]
struct Created {
id: String,
}
let created: Created = http::fetch(http::Request {
url: "https://api.example.com/leads".to_string(),
method: Method::Post,
headers: http::headers(&[("Content-Type", "application/json")]),
body: Some(json!({ "email": "lead@example.com" })),
})?;
assert_eq!(created.id, "L1");Fields§
§url: StringThe address to call. Required, and trimmed before it is sent.
method: MethodWhat to do to the resource. GET unless something else is named.
headers: HashMap<String, String>The headers to send, as they are written.
body: Option<Value>The body to send.
A Value::String is the body itself, so a form-encoded or already
rendered payload arrives byte for byte. Anything else is sent as its
JSON text.
Trait Implementations§
Source§impl Debug for Request
impl Debug for Request
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
The call, and never what authorises it.
A request carries credentials in two places an author does not think of as
secret-shaped: Authorization is an ordinary entry in headers, and a
token exchange puts a client secret in the body. Both would reach a log
line through an ordinary {:?}.
So the header NAMES are rendered and their values are not, and the body is
rendered as its size. Nothing is hidden from the author – both fields are
public and print in full when asked for directly – and what changes is
only what an incidental {:?} of the whole request discloses.
use simpleplatform_sdk::http::{self, Method, Request};
let request = Request {
url: "https://api.example.com/leads".to_string(),
method: Method::Get,
headers: http::headers(&[("Authorization", "Bearer t-1234")]),
body: None,
};
assert!(!format!("{request:?}").contains("t-1234"));
assert!(format!("{request:?}").contains("Authorization"));