[Flask] bind route to object method

Robert Wikman rbw at vault13.org
Wed Oct 10 19:42:04 EDT 2018


Hello,

You could create a custom @decorator for your controllers that deserializes
`request.get_json()` and parses `request.url`, then passes the results to
your `o.process()` method.
Check or the Furl and Marshmallow libraries to help out with this.

..or perhaps https://github.com/rbw/flask-journey if you're lazy ;)

--
Robert Wikman
0xf6feb506ae5d3762


On Thu, Oct 11, 2018 at 12:19 AM Philipp Kraus <
philipp.kraus at tu-clausthal.de> wrote:

> Hello,
>
> I’m new with Flask, but I try to bind a list of objects to routes. Each
> object has got a part of the url. In general it should be
>
> objectlist = getObjects()
> for o in objectless:
>         app.route( "/api/„ + o.name + „process“, methods=[„POST“], - here
> I need a call that the process method of o is called and the JSON data from
> the POST body and url parameters are parsed -  )
>
> Each object o has got a method with the signature o.process( body={},
> params={} ) and process returns also a dict.
> So how I can create the JSON deserialization from the POST body, extract
> the url parameters to a dict and pass all the data to my object method and
> how can I send the result of the method as JSON structure back?
>
> Thanks
>
> Phil
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20181011/98ee1608/attachment.html>


More information about the Flask mailing list