pub struct Request {
pub url: String,
pub method: Method,
pub headers: HashMap<String, String>,
pub body: Option<Value>,
pub credentials: Option<Credentials>,
}Expand description
One outbound request.
Every field has a default — GET, no headers, no body, no credentials
mode — 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" })),
..http::Request::default()
})?;
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.
credentials: Option<Credentials>Whether a request made from the browser carries the page’s cookies and
HTTP authentication. None names no mode, and the browser host then
omits them. See Credentials.
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")]),
..Request::default()
};
assert!(!format!("{request:?}").contains("t-1234"));
assert!(format!("{request:?}").contains("Authorization"));