Some APIs allow sending a request either as a GET request or POST request. For those that allow sending as a GET request, a request body may not always need to be provided.
With the current implementation, an API that can send a POST request will model the inputs with a generic builder struct, where the generic type parameter is the body type. Take for example, search
With the current implementation, the generic type parameter B forms part of the search() function that returns the builder to build the request, meaning a user has to provide some value like () (unit), even if they may not be sending a request body, such as in the case of a GET request. This implementation can be changed to make search non-generic, and body on Search<B> generic
// 1. Make search() non-generic and return Search<()> by default
pub fn search(&self) -> Search<()>
where
B: Serialize,
{
Search::new(self.clone())
}
// 2. Make body() generic and return new Search<B> when body set
#[doc = "The body for the API call"]
pub fn body<B>(mut self, body: Option<B>) -> Search<B> {
Search {
client: self.client,
_source: self._source,
_source_excludes: self._source_excludes,
//... assign all fields
body: body,
}
}
Some APIs allow sending a request either as a GET request or POST request. For those that allow sending as a GET request, a request body may not always need to be provided.
With the current implementation, an API that can send a POST request will model the inputs with a generic builder struct, where the generic type parameter is the body type. Take for example,
search
With the current implementation, the generic type parameter
B
forms part of thesearch()
function that returns the builder to build the request, meaning a user has to provide some value like()
(unit), even if they may not be sending a request body, such as in the case of a GET request. This implementation can be changed to makesearch
non-generic, andbody
onSearch<B>
genericThis can be generated from the REST API spec