I have a question about whether I’m building an API call in a way that makes sense.
For now, I have something like:
let request = Request::new() .command(Command::AgencyList) .route("one") .create_request() .unwrap(); let mut res = request.send().unwrap();
The intermediate type from create_request is:
pub fn create_request(&self) -> Result<ApiCall>
ApiCall is a simple wrapper around
Url which validates that it’s a correct API call.
An alternative would look more like:
let res = Request::new() .command(Command::AgencyList) .route("one") .send() .unwrap();
Which has the advantage of being more compact. And perhaps makes more sense? I would perform validation that the API call is correct in
.send(). One downside I noticed is that I lost the unit tests I was writing to make sure that the correct Url was being created, since this goes straight to sending an HTTP request.
Any thoughts on which way is better? Or if there’s an even better way? Also, let me know if I wasn’t clear in explaining the question.