π¦Sending Body/Data
When sending HTTP requests, a common requirement is to attach a payload/body to POST, PUT, or PATCH requests, like JSON, XML or multipart data. Saloon makes this easy for you with built-in body traits.
Getting Started
To get started, you will need to add the HasBody
interface to your request. This interface is required as it tells Saloon to look for a body()
method supplied by one of the body traits. Without this interface, Saloon will not send any request body to the HTTP client. Also make sure to change your method to POST, PUT or PATCH depending on the requirements of the API.
Next, you will need to add a trait to provide an implementation for the missing body()
method. Saloon has a trait for all the common types of request bodies.
Continue reading below to understand more about the specific body type that you need.
JSON BodyMultipart Form BodyStream BodyForm Body (URL Encoded)XML BodyString / Plain Text BodyLast updated