New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds head/2 and head/3 to PhoenixController. #818
Adds head/2 and head/3 to PhoenixController. #818
Conversation
This adds head/2 and head/3 convenience functions for returning empty responses with just a status code and optionally a specific content type. Examples: iex> head conn, 200 iex> head conn, :ok iex> head conn, :ok, "application/json"
I am a bit unsure about this addition:
In other words, this doesn't look like it fits the rest of the controller API. Also, I would propose Thank you @SteveAquino! |
:+1 to what @josevalim said. |
Does Am I missing something? |
|
The idea of this function is to, as chris pointed out, simplify an empty response. Sometimes that isn't necessarily a 204 (for example, a 401 unauthorized), and I imagine this is fairly common in API based applications. Also, this was intended to be inline with Finally, and maybe this isn't a good reason, but the inspiration came from rails land were you can call Given that, I would recommend at least |
@josevalim Just realized I did not address one of your comments, but Thanks for all the feedback! |
It doesn't just in the fact it receives the status code while the functions above do not. Thanks for taking the time to improve Phoenix and participate in the discussion! :) |
A few questions I have: I don't come from a Rails background so while the name may seem obvious to most - it leaves me quite baffled.
Is there a reason for the name other than "Rails did it"? My 2nd question, and I wish I could check the codebase for the answer now but the wifi in this hotel is absolutely terrible: why can't we just have It seems to me that this adds a level of indirection for doing a really simple thing. To me |
@djm The name is entirely inspired by Rails, but I see your point about this being confusing, especially given the Erlang/Elixir terminology. Also I see @josevalim's point about sending the status code being inconsistent with the other APIs. The reason I suggested this function was because it took me a long time to figure out how to send an empty response, so maybe the documentation needs improving more than the code. Also I feel like I'm not sure the correct approach here, but it seems like SOMETHING is missing, perhaps we just need to add an example to the docs and call it a day, because really that's what tripped me up. |
Maybe we should clarify that the functions in Plug.Conn are essential for using Phoenix.Controller effectively? |
Personally I feel like I understood the relationship between Plug and Phoenix.Controller, but I think that what really tripped me up is that I was looking in the guide for an example and couldn't find one. Eventually I was able to find it in the hex docs, but I think that maybe a simple example would really help folks. |
Just adding my two cents. but I believe there should really be a strong link or pointing to the fact that Phoenix uses Plugs underneath and that sometimes the functions you may not see in the Phoenix documentation will be available in the Plug documentation. Usually that seems to be what trips people up; mostly we all seem to forget about checking the Plug docs .. |
@SteveAquino, I would love to make this more clear for you and others. If I understand correctly, you're asking for examples of @2kodes, I would love to clarify the issue you brought up as well. We do have this guide for Plug: Are you suggesting we just add a bit suggesting folks remember to look in the Plug documentation as well if they can't find what they are looking for in the Phoenix docs? Again, if I'm getting that wrong, please open an issue or submit a PR to the guides repo. Thanks! |
@lancehalvorsen Yes, I think an example of using |
Ok, I created 2 issues in the guides repo (as we can see above). |
Thanks @lancehalvorsen. I think we can shelve this and focus on handling it on the guides side. |
This adds head/2 and head/3 convenience functions for returning empty responses with just a status code and optionally a specific content type. Per this thread on phoenix-talk: https://groups.google.com/forum/#!topic/phoenix-talk/110izD_r-Zw
Examples: