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

Support for other web frameworks #1

Open
tclasen opened this issue Jan 3, 2022 · 6 comments
Open

Support for other web frameworks #1

tclasen opened this issue Jan 3, 2022 · 6 comments

Comments

@tclasen
Copy link

tclasen commented Jan 3, 2022

Hey, I love the concept and implementation of this package, but I'm not fond of Flask. Would it be possible to remove flask as a dependency and instead abstract out the routing system so it can be plugged into any framework? Specifically I'd love to use this with FastAPI.

@HUSKI3
Copy link
Owner

HUSKI3 commented Jan 3, 2022

Sure! I'll move all the component building over to the composite class instead of serve. Currently Flask is just a placeholder and I wanted to move the library over to raw wsgi. Once I'm done separating out the two components I'll post an update with a how-to in this issue!

@HUSKI3
Copy link
Owner

HUSKI3 commented Jan 4, 2022

Done!
Here's an example. I don't have a broad enough knowledge of FastAPI so please bare with this relatively simple approach.

# Create our Composite pages
Pages = Composite(Homepage, About, debug = True)

from fastapi import FastAPI, Response

app = FastAPI()

# You can check all page info by printing the Composite component
print(pages)

# You can also get page info by querying it's route,
# NOTE: The routes do not contain the initial '/' 
print(pages.get(''))

@app.get("/")
def root():
   # By invoking run on a built page we can fetch the raw html from the dedicated builder function
   source = pages.get('').run()
   return Response(content=source, media_type="text/html") 

@app.get("/about")
def about():
   # By invoking run on a built page we can fetch the raw html from the dedicated builder function
   source = pages.get('about').run()
   return Response(content=source, media_type="text/html") 

Please do tell me if there are any other things you would like to be added/changed!

@HUSKI3
Copy link
Owner

HUSKI3 commented Jan 12, 2022

Marking as closed due to no activity! Please do open a new issue if you have any other requests!

@HUSKI3 HUSKI3 closed this as completed Jan 12, 2022
@tclasen
Copy link
Author

tclasen commented Jan 12, 2022

Hey, sorry for not responding in time. The changes look great, but now you have the install of 2 different web frameworks in the main dependencies of the project. Would it be possible to move them to "extras" so that you can do a pip install perry[flask] or a pip install perry[fastapi]?

@HUSKI3
Copy link
Owner

HUSKI3 commented Jan 13, 2022

Sure, I'll look into that. I'll be starting to move it into a proper PyPi package soon. I do not recommend using the poetry deps inside this project as they are an utter mess lol. I'll fix it up for distribution soon though!

@HUSKI3 HUSKI3 reopened this Jan 13, 2022
@tclasen
Copy link
Author

tclasen commented Jan 13, 2022 via email

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

No branches or pull requests

2 participants