Skip to main content

Request

Struct Request 

Source
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: String

The address to call. Required, and trimmed before it is sent.

§method: Method

What 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 Clone for Request

Source§

fn clone(&self) -> Request

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

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"));
Source§

impl Default for Request

Source§

fn default() -> Request

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.