Skip to main content

submit

Macro submit 

Source
macro_rules! submit {
    ($method:expr, $input:expr, $url:expr, &$client:ident) => { ... };
    ($method:expr, $input:expr, $url:expr, $headers:expr, &$client:ident) => { ... };
}
Expand description

Submit a request to the specified URL.

The submit! macro is a more generic version of the get! macro. Its first argument is a string literal or a variable. Arrows are used to specify the body serialization type and the output type.

You can use the JsonBody, XmlBody, MsgPack type for JSON, XML and MessagePack serialization.

To help understand the macro arguments, here is an example:

fetch!(url, &mut client, body, ty)

§Arguments

  • method - The HTTP method to use.
  • input - The input to send with request.
  • url - The URL to make the GET request to.
  • headers - The headers to send with request.
  • client - The client variable to use for request.
  • res_body_ty - The body serialization format of response.
  • res_ty - The type of response.

Please note url can be a string literal or a variable.

§Example

let client = Client::new();
let response = submit!("POST", "user=deboa", "https://jsonplaceholder.typicode.com/posts", &client);
assert_eq!(response.id, 1);