http
http copied to clipboard
Implement `Response` builder helper fns
Just like Request has get, post, etc... helper fns, there should be equivalent helpers for Response.
I was looking at this and was about to begin but it dawned on me that responses don't have verbs. What are the helpers that should be built?
Response::ok() -> Builder etc... probably.
It's just a bit nicer than pulling in StatusCode.
Ah, that makes sense!
Is there a need for Response::ok()? The default status code is already OK, either with Response::new(body), or with Response::builder().
Well, I think that there is definitely use for other common status code helpers, and having ok seems useful for consistency (or someone will be looking for a while through the docs wondering why it isn't there).
It sounds like it's a question of explicitness vs implicitness. I am curious which other response codes make sense to add. My pr #154 has several, but not all, implemented.
I still am leaning towards being defensive and careful about what we expose on integral types of the library. I'm less worried about methods that may be on the builders themselves. As such, what if these things were just that, methods on the builder, instead of Response?
Response::builder()
.created()
Response::builder()
.not_found()
// etc
The other options are:
Builder::created()
// ...
.build(..)
response::created()
// ...
.build(..)
Of course, this doesn't mirror Request, which is part of what I was hoping to do.
The options I lean towards, in order are:
- As methods on the builder:
Response::builder().not_found() - As constructors on the builder:
Builder::not_found()
I do think that we should have a mirror for request builder, but I think that instead of following Request::get(), Request::post, that the request side should instead change to be either 1 or 2 above.
Is there still strong desire for this? With 0.2 coming, I'd rather propose we don't do this, and remove the ones that exist for Request.
@seanmonstar why remove?
It would be useful to have From<StatusCode> for Response<Body>. I often need to create a response from a status code.