Add syntatic sugar for route registration#3907
Conversation
dd8c2de to
5caf74a
Compare
|
What I dislike with this approach is that - at least when you aren't writing a RESTful API - there is a very good chance that you need endpoints handling both GET and POST (render form if not submitted or validation failed, otherwise do stuff). In fact, in a classic webapp with lots of forms it's probably the most common thing after GET endpoints... However, this case is not covered by the shortcuts and I can't think of any decent name for a method that does cover it... And I think beginners may think mixed-method routes are discouraged because of this, making them do weird stuff with the session for the basic web form usecase described above... |
|
I believe the test failures are unrelated. I think the existing |
This takes a popular API whereby instead of passing the HTTP method as
an argument to route it is instead used as the method name i.e.
@app.route("/", methods=["POST"])
is now writeable as,
@app.post("/")
This is simply syntatic sugar, it doesn't do anything else, but makes
it slightly easier for users.
I've included all the methods that are relevant and aren't auto
generated i.e. not connect, head, options, and trace.
|
Refactored to avoid repeating the error message in each method. Changed to a |
|
Glad to see this finally merged! After I proposed this idea and was declined in the first pallets meeting, I started to make the REST API extension I'm developing to become a framework so that I can inherit the |
I know we briefly discussed this, but I'd like to make the case with a concrete implementation. My argument is that this is actually quite a nice API and requires little implementation (especially now with the nice Scaffold). There is also precedent, in my view, that the test client also has this API. (Also, everyone copies Flask so lets copy them :p).
Commit message
This takes a popular API whereby instead of passing the HTTP method as
an argument to route it is instead used as the method name i.e.
is now writeable as,
This is simply syntatic sugar, it doesn't do anything else, but makes
it slightly easier for users.
CHANGES.rstsummarizing the change and linking to the issue... versionchanged::entries in any relevant code docs.pre-commithooks and fix any issues.pytestandtox, no tests failed.