Skip to content
Myr

views.rst

This file

Path

docs/views.rst

324 lines · 10.0 KiB

Last changed by

Merge branch '2.2.x'David Lordbefore adoption7464e17

History of this file

Take it

The walk stopped after 200 commits: lines older than 48ee204 point at it.

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 1–2why, one step back
1Class-based Views
2=================

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 3why, one step back
3

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 4why, one step back
4.. currentmodule:: flask.views

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 5why, one step back
5

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 6–7why, one step back
6This page introduces using the :class:`View` and :class:`MethodView`
7classes to write class-based views.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 8why, one step back
8

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 9–12why, one step back
9A class-based view is a class that acts as a view function. Because it
10is a class, different instances of the class can be created with11different arguments, to change the behavior of the view. This is also12known as generic, reusable, or pluggable views.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 13why, one step back
13

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 14–15why, one step back
14An example of where this is useful is defining a class that creates an
15API based on the database model it is initialized with.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 16why, one step back
16

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 17–31why, one step back
17For more complex API behavior and customization, look into the various
18API extensions for Flask.192021Basic Reusable View22-------------------2324Let's walk through an example converting a view function to a view25class. We start with a view function that queries a list of users then26renders a template to show the list.2728.. code-block:: python2930 @app.route("/users/")31 def user_list():

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 32why, one step back
32 users = User.query.all()

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 33why, one step back
33 return render_template("users.html", users=users)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 34why, one step back
34

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 35–38why, one step back
35This works for the user model, but let's say you also had more models
36that needed list pages. You'd need to write another view function for37each model, even though the only thing that would change is the model38and template name.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 39why, one step back
39

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 40–42why, one step back
40Instead, you can write a :class:`View` subclass that will query a model
41and render a template. As the first step, we'll convert the view to a42class without any customization.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 43why, one step back
43

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 44–45why, one step back
44.. code-block:: python
45

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 46–47why, one step back
46 from flask.views import View
47

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 48why, one step back
48 class UserList(View):

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 49–50why, one step back
49 def dispatch_request(self):
50 users = User.query.all()

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 51why, one step back
51 return render_template("users.html", objects=users)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 52why, one step back
52

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 53why, one step back
53 app.add_url_rule("/users/", view_func=UserList.as_view("user_list"))

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 54why, one step back
54

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 55–60why, one step back
55The :meth:`View.dispatch_request` method is the equivalent of the view
56function. Calling :meth:`View.as_view` method will create a view57function that can be registered on the app with its58:meth:`~flask.Flask.add_url_rule` method. The first argument to59``as_view`` is the name to use to refer to the view with60:func:`~flask.url_for`.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 61why, one step back
61

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 62why, one step back
62.. note::

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 63why, one step back
63

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 64–65why, one step back
64 You can't decorate the class with ``@app.route()`` the way you'd
65 do with a basic view function.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 66why, one step back
66

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 67–71why, one step back
67Next, we need to be able to register the same view class for different
68models and templates, to make it more useful than the original function.69The class will take two arguments, the model and template, and store70them on ``self``. Then ``dispatch_request`` can reference these instead71of hard-coded values.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 72why, one step back
72

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 73why, one step back
73.. code-block:: python

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 74why, one step back
74

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 75–78why, one step back
75 class ListView(View):
76 def __init__(self, model, template):77 self.model = model78 self.template = template

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 79–80why, one step back
79
80 def dispatch_request(self):

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 81–82why, one step back
81 items = self.model.query.all()
82 return render_template(self.template, items=items)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 83why, one step back
83

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 84–87why, one step back
84Remember, we create the view function with ``View.as_view()`` instead of
85creating the class directly. Any extra arguments passed to ``as_view``86are then passed when creating the class. Now we can register the same87view to handle multiple models.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 88why, one step back
88

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 89why, one step back
89.. code-block:: python

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 90why, one step back
90

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 91–98why, one step back
91 app.add_url_rule(
92 "/users/",93 view_func=ListView.as_view("user_list", User, "users.html"),94 )95 app.add_url_rule(96 "/stories/",97 view_func=ListView.as_view("story_list", Story, "stories.html"),98 )

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 99–100why, one step back
99
100

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 101–118why, one step back
101URL Variables
102-------------103104Any variables captured by the URL are passed as keyword arguments to the105``dispatch_request`` method, as they would be for a regular view106function.107108.. code-block:: python109110 class DetailView(View):111 def __init__(self, model):112 self.model = model113 self.template = f"{model.__name__.lower()}/detail.html"114115 def dispatch_request(self, id)116 item = self.model.query.get_or_404(id)117 return render_template(self.template, item=item)118

Merge branch '2.2.x'David Lordbefore adoption73b9bac

lines 119–122why, one step back
119 app.add_url_rule(
120 "/users/<int:id>",121 view_func=DetailView.as_view("user_detail", User)122 )

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 123–151why, one step back
123
124125View Lifetime and ``self``126--------------------------127128By default, a new instance of the view class is created every time a129request is handled. This means that it is safe to write other data to130``self`` during the request, since the next request will not see it,131unlike other forms of global state.132133However, if your view class needs to do a lot of complex initialization,134doing it for every request is unnecessary and can be inefficient. To135avoid this, set :attr:`View.init_every_request` to ``False``, which will136only create one instance of the class and use it for every request. In137this case, writing to ``self`` is not safe. If you need to store data138during the request, use :data:`~flask.g` instead.139140In the ``ListView`` example, nothing writes to ``self`` during the141request, so it is more efficient to create a single instance.142143.. code-block:: python144145 class ListView(View):146 init_every_request = False147148 def __init__(self, model, template):149 self.model = model150 self.template = template151

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 152why, one step back
152 def dispatch_request(self):

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 153–154why, one step back
153 items = self.model.query.all()
154 return render_template(self.template, items=items)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 155why, one step back
155

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 156–157why, one step back
156Different instances will still be created each for each ``as_view``
157call, but not for each request to those views.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 158–159why, one step back
158
159

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 160–195why, one step back
160View Decorators
161---------------162163The view class itself is not the view function. View decorators need to164be applied to the view function returned by ``as_view``, not the class165itself. Set :attr:`View.decorators` to a list of decorators to apply.166167.. code-block:: python168169 class UserList(View):170 decorators = [cache(minutes=2), login_required]171172 app.add_url_rule('/users/', view_func=UserList.as_view())173174If you didn't set ``decorators``, you could apply them manually instead.175This is equivalent to:176177.. code-block:: python178179 view = UserList.as_view("users_list")180 view = cache(minutes=2)(view)181 view = login_required(view)182 app.add_url_rule('/users/', view_func=view)183184Keep in mind that order matters. If you're used to ``@decorator`` style,185this is equivalent to:186187.. code-block:: python188189 @app.route("/users/")190 @login_required191 @cache(minutes=2)192 def user_list():193 ...194195

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 196–198why, one step back
196Method Hints
197------------198

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 199–202why, one step back
199A common pattern is to register a view with ``methods=["GET", "POST"]``,
200then check ``request.method == "POST"`` to decide what to do. Setting201:attr:`View.methods` is equivalent to passing the list of methods to202``add_url_rule`` or ``route``.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 203why, one step back
203

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 204–205why, one step back
204.. code-block:: python
205

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 206why, one step back
206 class MyView(View):

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 207why, one step back
207 methods = ["GET", "POST"]

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 208–209why, one step back
208
209 def dispatch_request(self):

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 210why, one step back
210 if request.method == "POST":

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 211–213why, one step back
211 ...
212 ...213

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 214why, one step back
214 app.add_url_rule('/my-view', view_func=MyView.as_view('my-view'))

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 215why, one step back
215

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 216–217why, one step back
216This is equivalent to the following, except further subclasses can
217inherit or change the methods.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 218why, one step back
218

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 219why, one step back
219.. code-block:: python

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 220why, one step back
220

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 221–225why, one step back
221 app.add_url_rule(
222 "/my-view",223 view_func=MyView.as_view("my-view"),224 methods=["GET", "POST"],225 )

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 226–227why, one step back
226
227

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 228–229why, one step back
228Method Dispatching and APIs
229---------------------------

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 230why, one step back
230

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 231–234why, one step back
231For APIs it can be helpful to use a different function for each HTTP
232method. :class:`MethodView` extends the basic :class:`View` to dispatch233to different methods of the class based on the request method. Each HTTP234method maps to a method of the class with the same (lowercase) name.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 235why, one step back
235

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 236–238why, one step back
236:class:`MethodView` automatically sets :attr:`View.methods` based on the
237methods defined by the class. It even knows how to handle subclasses238that override or define other methods.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 239why, one step back
239

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 240–242why, one step back
240We can make a generic ``ItemAPI`` class that provides get (detail),
241patch (edit), and delete methods for a given model. A ``GroupAPI`` can242provide get (list) and post (create) methods.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 243why, one step back
243

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 244why, one step back
244.. code-block:: python

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 245why, one step back
245

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 246why, one step back
246 from flask.views import MethodView

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 247why, one step back
247

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 248–249why, one step back
248 class ItemAPI(MethodView):
249 init_every_request = False

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 250why, one step back
250

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 251why, one step back
251 def __init__(self, model):

Fix missing assignment in MethodView example (#4815)waffle-stomperbefore adoption2c78771

line 252why, one step back
252 self.model = model

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 253why, one step back
253 self.validator = generate_validator(model)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 254why, one step back
254

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 255–256why, one step back
255 def _get_item(self, id):
256 return self.model.query.get_or_404(id)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 257why, one step back
257

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 258why, one step back
258 def get(self, id):

Merge branch '2.2.x'David Lordbefore adoption7464e17

line 259why, one step back
259 item = self._get_item(id)

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 260why, one step back
260 return jsonify(item.to_json())

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 261why, one step back
261

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 262–264why, one step back
262 def patch(self, id):
263 item = self._get_item(id)264 errors = self.validator.validate(item, request.json)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 265why, one step back
265

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 266–267why, one step back
266 if errors:
267 return jsonify(errors), 400

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 268why, one step back
268

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 269–271why, one step back
269 item.update_from_json(request.json)
270 db.session.commit()271 return jsonify(item.to_json())

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 272why, one step back
272

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 273–277why, one step back
273 def delete(self, id):
274 item = self._get_item(id)275 db.session.delete(item)276 db.session.commit()277 return "", 204

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 278why, one step back
278

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 279–280why, one step back
279 class GroupAPI(MethodView):
280 init_every_request = False

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 281why, one step back
281

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 282–284why, one step back
282 def __init__(self, model):
283 self.model = model284 self.validator = generate_validator(model, create=True)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 285why, one step back
285

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 286–288why, one step back
286 def get(self):
287 items = self.model.query.all()288 return jsonify([item.to_json() for item in items])

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 289–290why, one step back
289
290 def post(self):

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 291why, one step back
291 errors = self.validator.validate(request.json)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 292why, one step back
292

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 293–294why, one step back
293 if errors:
294 return jsonify(errors), 400

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 295why, one step back
295

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 296–298why, one step back
296 db.session.add(self.model.from_json(request.json))
297 db.session.commit()298 return jsonify(item.to_json())

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 299why, one step back
299

Fix argument in `register_api()` in docs/view.rst (#4818)Maksim Salaubefore adoption9c3deee

line 300why, one step back
300 def register_api(app, model, name):

Merge branch '2.2.x'David Lordbefore adoption73b9bac

lines 301–304why, one step back
301 item = ItemAPI.as_view(f"{name}-item", model)
302 group = GroupAPI.as_view(f"{name}-group", model)303 app.add_url_rule(f"/{name}/<int:id>", view_func=item)304 app.add_url_rule(f"/{name}/", view_func=group)

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 305why, one step back
305

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 306–307why, one step back
306 register_api(app, User, "users")
307 register_api(app, Story, "stories")

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 308why, one step back
308

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

line 309why, one step back
309This produces the following views, a standard REST API!

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 310why, one step back
310

Merge pull request #4624 from pallets/view-init-scopeDavid Lordbefore adoptiondb3187f

lines 311–324why, one step back
311================= ========== ===================
312URL Method Description313----------------- ---------- -------------------314``/users/`` ``GET`` List all users315``/users/`` ``POST`` Create a new user316``/users/<id>`` ``GET`` Show a single user317``/users/<id>`` ``PATCH`` Update a user318``/users/<id>`` ``DELETE`` Delete a user319``/stories/`` ``GET`` List all stories320``/stories/`` ``POST`` Create a new story321``/stories/<id>`` ``GET`` Show a single story322``/stories/<id>`` ``PATCH`` Update a story323``/stories/<id>`` ``DELETE`` Delete a story324================= ========== ===================