Skip to content
Myr

Merge pull request #345 from jimrollenhagen/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix issue #338

authored by Armin Ronacher · committed by Armin Ronacher · parents d628df6, e345a3a · Browse files · 1 file+5 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−3 removed

  • other:+5 added−3 removed

1 file+5 added−3 removed

modified:docs/views.rst+5 added-3 removed
208 unmodified lines
209and explicitly mentioning the methods for each::210211 user_view = UserAPI.as_view('user_api')212 app.add_url_rule('/users/', defaults={'user_id': None},213 view_func=user_view, methods=['GET', 'POST'])213 view_func=user_view, methods=['GET',])214 app.add_url_rule('/users/', view_func=user_view, methods=['POST',])215 app.add_url_rule('/users/<int:user_id>', view_func=user_view,216 methods=['GET', 'PUT', 'DELETE'])217218If you have a lot of APIs that look similar you can refactor that
1 unmodified line
220221 def register_api(view, endpoint, url, pk='id', pk_type='int'):222 view_func = view.as_view(endpoint)223 app.add_url_rule(url, defaults={pk: None},223 view_func=view_func, methods=['GET', 'POST'])224 app.add_url_rule('%s<%s:%s>' % (url, pk), view_func=view_func,224 view_func=view_func, methods=['GET',])225 app.add_url_rule(url, view_func=view_func, methods=['POST',])226 app.add_url_rule('%s<%s:%s>' % (url, pk, pk_type), view_func=view_func,227 methods=['GET', 'PUT', 'DELETE'])228229 register_api(UserAPI, 'user_api', '/users/', pk='user_id')