Live data from Hacker News

Flask API – Browsable Web APIs for Flask

flaskapi.org

21–30 of 50 posts

Re: Flask API – Browsable Web APIs for Flask

#21

Absolutely amazing stuff been looking for something like django rest framework on Flask. Any dates for 1.0 release? I'm looking forward to the authentication and such. What would be great is also some implementation of Sandman's auto inspection of database to create REST api, with support for One to Many, Many to Many relationships. Great job!

> Any dates for 1.0 release?

If anyone wants to give me a coupla days paid work on this, then yah I'm sure that could be arranged. :)

Re: Flask API – Browsable Web APIs for Flask

#22
post #2

Why use this and not Flask-RESTful? How is the use case different? http://flask-restful.readthedocs.org/en/latest/

The most obvious feature difference is the browsable API. Flask API also shares the same architecture as the core of Django REST framework, which I think just has a really nice separation of concerns. Also the interface of `request.data` means is easy to transparently support both JSON and form requests, and the nice content negotiation on responses means it's easy to build services that power both an HTML front-end…

Perhaps an obvious question, but why do APIs need to be browsable?

Re: Flask API – Browsable Web APIs for Flask

#23
post #2

Why use this and not Flask-RESTful? How is the use case different? http://flask-restful.readthedocs.org/en/latest/

The most obvious feature difference is the browsable API. Flask API also shares the same architecture as the core of Django REST framework, which I think just has a really nice separation of concerns. Also the interface of `request.data` means is easy to transparently support both JSON and form requests, and the nice content negotiation on responses means it's easy to build services that power both an HTML front-end…

What about using Swagger[0] with flask-restful-swagger[1]?

[0] https://helloreverb.com/developers/swagger [1] https://github.com/rantav/flask-restful-swagger

Re: Flask API – Browsable Web APIs for Flask

#24
post #3

Token auth in flask is something I was going to work on soon. It should be straightforward to use a decorator to protect restricted pages. One thing I am absolutely not clear yet is how you keep the user logged if the token expires after x seconds. I mean, if the user is using the app, somehow the token expiring date should be constantly updated, right? All this would be amazing coupled with angularjs… Edit Oh, and I…

> It should be straightforward to use a decorator to protect restricted pages. Authentication policies will use a similar style to the renderers and parsers (and all of REST framework). You'll be able to set them per-view with a decorator, or set them system-wide in the config. You'll also be able to support multiple authentication policies.

Long story short - I went full hipster on that grunt + yeoman + bower + angular ui and my conclusion is http://i3.kym-cdn.com/photos/images/newsfeed/000/439/835/47c...

Too much complexity added to project. Going REST patch is problematic when you have to integrate with with server-render style lib or service. SEO is shit. Angular doc is worse.

Auth is base on tokens, no sessions. I reused the ideas from here https://github.com/mrgamer/angular-login-example

def auth_required(f): @wraps(f) def wrapper(args, *kwargs): token = request.headers.get("X-Token") if token is None: abort(400) user = User.verify_auth_token(token, app.config["SECRET_KEY"])

If you don't make very heavy SPA like photoshop, don't use angular.

Re: Flask API – Browsable Web APIs for Flask

#25
post #17

I spent last 3 months building AngularJS + Flask where the client talks to server only through REST. There were 3 options: 1. Bare Flask 2. Flask RESTful 3. Flask Restless I've spent quite some time investigating 2nd and 3rd options. Problems with 2nd: a) Didn't bring much to the table comparing to pure Flask. Extra abstraction and complexity that without much improvements b) Swallowing Flask exceptions c) Risk that…

> one example returns json array, what about JSON venerability?

Side point: I don't have a reference for this, but from what I understand the JSON array vulnerability has long since been closed in all sane browsers.

Re: Flask API – Browsable Web APIs for Flask

#26
post #18
post #17

I spent last 3 months building AngularJS + Flask where the client talks to server only through REST. There were 3 options: 1. Bare Flask 2. Flask RESTful 3. Flask Restless I've spent quite some time investigating 2nd and 3rd options. Problems with 2nd: a) Didn't bring much to the table comparing to pure Flask. Extra abstraction and complexity that without much improvements b) Swallowing Flask exceptions c) Risk that…

> I spent last 3 months building AngularJS + Flask where the client talks to server only through REST. I've been wanting to do something like this for a certain time, so I have a few questions if you don't mind. How do you handle authentication? Tokens? Cookies? Is there a special "API key" for your web app?

Long story short - I went full hipster on that grunt + yeoman + bower + angular ui and my conclusion is http://i3.kym-cdn.com/photos/images/newsfeed/000/439/835/47c...

Too much complexity added to project. Going REST patch is problematic when you have to integrate with server-render style lib or service. SEO is shit. Angular doc is worse.

Auth is base on tokens, no sessions. I reused the ideas from here https://github.com/mrgamer/angular-login-example

def auth_required(f):

  @wraps(f)

  def wrapper(*args, **kwargs):

    token = request.headers.get("X-Token")

    if token is None:

      abort(400)

    user = User.verify_auth_token(token, app.config["SECRET_KEY"])
....

If you don't make very heavy SPA like photoshop, don't use angular.

Re: Flask API – Browsable Web APIs for Flask

#27
post #22

Earlier quoted context omitted.

The most obvious feature difference is the browsable API. Flask API also shares the same architecture as the core of Django REST framework, which I think just has a really nice separation of concerns. Also the interface of `request.data` means is easy to transparently support both JSON and form requests, and the nice content negotiation on responses means it's easy to build services that power both an HTML front-end…

Perhaps an obvious question, but why do APIs need to be browsable?

They don't need too, but it sure-as-hell improves accessibility & usability.

Re: Flask API – Browsable Web APIs for Flask

#28
post #3

Token auth in flask is something I was going to work on soon. It should be straightforward to use a decorator to protect restricted pages. One thing I am absolutely not clear yet is how you keep the user logged if the token expires after x seconds. I mean, if the user is using the app, somehow the token expiring date should be constantly updated, right? All this would be amazing coupled with angularjs… Edit Oh, and I…

I use Miguel Grinberg's "Token Based Authentication" example[1]. It's based on itsdangerous's TimedJSONWebSignatureSerializer class and it works very well in practice.

[1] http://blog.miguelgrinberg.com/post/restful-authentication-w...

Re: Flask API – Browsable Web APIs for Flask

#29
post #2

Why use this and not Flask-RESTful? How is the use case different? http://flask-restful.readthedocs.org/en/latest/

I can sort of comment on this since I've used Flask-RESTful and Django REST Framework where a lot of the Flask-API design is/will be borrowed from. I think the browsable API feature is great but it's not the killer feature for me. To me the killer feature is the well-designed serialization and validation architecture. In Flask-RESTful this seems half-baked - there is no notion of hyperlinked references or nested objects. At our company we ended up implementing our own serialization & validation layer which felt a lot like reinventing the wheel. My hope is that we can bring this same great architecture over from DRF to Flask-API.

Re: Flask API – Browsable Web APIs for Flask

#30
post #17

I spent last 3 months building AngularJS + Flask where the client talks to server only through REST. There were 3 options: 1. Bare Flask 2. Flask RESTful 3. Flask Restless I've spent quite some time investigating 2nd and 3rd options. Problems with 2nd: a) Didn't bring much to the table comparing to pure Flask. Extra abstraction and complexity that without much improvements b) Swallowing Flask exceptions c) Risk that…

You should check out eve (http://python-eve.org) - it's amazing for rapid prototyping (if the fact it requires Mongo isn't an issue).

I'm building an AngularJS + REST server using Eve for the server. It has saved me so much time that I'm putting my dev effort mainly into a comprehensive test suite because there's so little dev work to do (btw - I'm not the author, it's just the fastest framework I've found for developing REST APIs - and I've tried Django REST framework & tastypie).

Post reply on HN