Macro anterofit::fields
[−]
[src]
macro_rules! fields { ($($key:expr $(=> $val:expr)*),*) => { ... }; }
Serialize a series of fields as the request body (form-encode them).
Each field can be a key-value pair, or a single identifier. The key (field name) should be a
string literal, and the value can be anything that is Display
.
For a single identifier, the identifier will be stringified for the field name, and its value will become the field value:
service! { pub trait RegisterService { fn register(&self, username: &str, password: &str) { POST("/register"); fields! { "username" => username, // Equivalent to "password" => password password } } } }
By default, this will serialize to a www-form-urlencoded
body.
However, if you use the path!()
or stream!()
macros as a value expression,
it will transform the request to a multipart/form-data
request.
Overwrites Body
Setting a new body will overwrite any previous body on the request.
Panics
If the request is a GET request (cannot have a body).
In some server stacks (e.g. PHP), these would be called POST
parameters.