Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a more complete example #62

Closed
Sytten opened this issue Feb 18, 2019 · 19 comments
Closed

Create a more complete example #62

Sytten opened this issue Feb 18, 2019 · 19 comments
Assignees
Labels
wip A work in progress

Comments

@Sytten
Copy link

Sytten commented Feb 18, 2019

I just discovered flask-rebar and I think it could very well become the new standard for REST with flask. The documentation is very well made, but a more complete "real-life" example/template would help a lot to get started. I am creating one for my project that i could share, but I don't know all the best practices for the framework.
Keep up the good work, cheers!

@Sytten Sytten changed the title Create a more complete exemple Create a more complete example Feb 18, 2019
@Sytten
Copy link
Author

Sytten commented Feb 18, 2019

One issue I faced for example is when having separate controller files, the paths would not be registered properly when creating the app because the file was loaded after the init_app

@barakalon
Copy link
Contributor

Hi @Sytten ! Thanks for the support.

Ah, yes. Import order can be tricky with the registry pattern. The trick that I usually see is:
(1) one module where rebar and its handler registries are instantiated
(2) handler module import that module
(3) the module that initializes the app imports all handler files

Roughly:

registry.py

import flask_rebar

rebar = flask_rebar.Rebar()
registry = rebar.create_handler_registry()

foo_handler.py

import .registry

@registry.handles("/foo")
def get_foo():
    ...

app.py

from flask import Flask

from .registry import rebar
from .foo_handler import get_foo  # noqa

def create_app(name):
    app = Flask(name)
    rebar.init_app(app)
    return app

But you are correct - this deserves its own example! Similar to #11

@Sytten
Copy link
Author

Sytten commented Feb 18, 2019

Thanks! Yes I figured it out eventually. If my team ends up choosing rebar, I will most certainly write a tutorial for it.
I am considering mixing it with https://github.com/justanr/marshmallow-annotations to generate Schema from dataclass and using the dataclass in the post_load to have a full object instead of a plain dict. Not sure how nicely it would play with the swagger generator though.

@barakalon
Copy link
Contributor

I don't know much about https://github.com/justanr/marshmallow-annotations nor if it would work with flask-rebar out of the box, but flask-rebar does support pluggable marshmallow-to-swagger converters: https://flask-rebar.readthedocs.io/en/latest/quickstart/swagger_generation.html#custom-marshmallow-types

@Sytten
Copy link
Author

Sytten commented Feb 18, 2019

Interesting, I will check that in due time. Probably need to create a custom authenticator for cognito too eventually, I could probably share it as an extension. Feel free to close the issue or keep it open, I might ramble more thoughts as we go in our project :D
BTW Plangrid should really write a blog post on rebar, I didn't see any on the engineering blog. Could help the project if it goes top on HN.

@RookieRick
Copy link
Contributor

Thanks @Sytten - I'm taking over maintenance of Flask-rebar here; will leave this one open for now as I'm a big fan of rambled thoughts :D One of the things I'm doing is ensuring each open Issue has an assignee, for now will just assign this one to you (and will look forward to seeing what examples you build if you end up writing that tutorial!)

@Sytten
Copy link
Author

Sytten commented Feb 28, 2019

Good to hear! We decided to go with rebar, so it's very likely that I will write something about it during the year. My next challenge is to integrate it with cognito authentication.

@Sytten
Copy link
Author

Sytten commented Mar 31, 2019

Ok it has started, if you guys have time to proof read I would appreciate (english is not my native language :S): https://medium.com/@emilefugulin/creating-a-production-ready-python-rest-backend-with-flask-rebar-part-1-62f498d2f077

@RookieRick
Copy link
Contributor

This looks really good so far! Will have to figure out the best place(s) to link to it from our docs as I'm sure others will find this helpful when Flask-Rebar becomes the de facto standard for Flask frameworks! :D

@twosigmajab
Copy link
Contributor

OT but...

BTW Plangrid should really write a blog post on rebar, I didn't see any on the engineering blog. Could help the project if it goes top on HN.

humiaozuzu/awesome-flask#162

hope this helps spread the word!

@Sytten
Copy link
Author

Sytten commented Apr 4, 2019

Good initiative @twosigmajab!
I will try to release my second article as soon as I find some time to finish it.
To gain some traction, we should also comment on flask-restplus and other abandoned frameworks to encourage people to check it.
Finishing OpenAPI 3.0 would help though :P

@RookieRick
Copy link
Contributor

OMG you guys are the best :) <3
I still don't have a date-certain but OpenAPI 3.0 is very much on the radar now so .. .SOON! :D (and for bonus points, I figured I'd write a PlanGrid blog post to "announce" it when it's done ;)

@Sytten
Copy link
Author

Sytten commented May 7, 2019

@Sytten
Copy link
Author

Sytten commented May 9, 2019

@RookieRick @barakalon Let me know what you guys think of it :)

@barakalon
Copy link
Contributor

Love it!

I'm also happy to make comments on typos and other small things, if you care. I think Medium has a draft link? Or maybe thats only prior to publishing.

@RookieRick
Copy link
Contributor

I started reading it and got pulled off on something else yesterday but looked pretty good so far! I'll try to get back to it shortly. Thanks again for putting this together btw!

@Sytten
Copy link
Author

Sytten commented May 10, 2019

@barakalon Feel free to send a list, I think the draft link is disabled since its published.
@RookieRick My pleasure :)

@RookieRick
Copy link
Contributor

Looks great - one suggestion: I'd go back and add a link to part 2 at the end of part 1 to make it easy for people to follow through the series.

@RookieRick RookieRick added the wip A work in progress label May 22, 2019
@twosigmajab
Copy link
Contributor

(Anyone want to send a quick PR to https://github.com/apisyouwonthate/openapi.tools to get Flask-Rebar listed on https://openapi.tools?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wip A work in progress
Projects
None yet
Development

No branches or pull requests

5 participants