-
Notifications
You must be signed in to change notification settings - Fork 130
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
FEAT: Add prototype of dynamic routes in hydrus #456
base: develop
Are you sure you want to change the base?
Conversation
the functions have been defined in app.py and not been imported from any other file is to avoid the circular dependency issues in flask at the prototype stage. I will fix this issue once the prototype is accepted related to HTTP-APIs#404
There are PEP-8 warnings. Please check here |
Ignored the import error E402 for flake8 to set the PYTHONPATH before all imports are finished.
@Mec-iS Fixed the PEP8 issues. For now, I have ignored the import error E402 by flake8 as I wanted to append to the PYTHONPATH variable for fixing imports. |
How it handles GET request with query parameters? |
I have not implemented that yet. I was just waiting for general approval on my approach. |
@vddesai1871 I just realized that the above implementation could also handle GET request with query parameters. The query parameters can be accessed by the user with |
This is a POC of having dynamic routes in hydrus. For the prototype I am showing only how a custom before request function can be added for a specific route, this can easily be extended to for after request function also. I have used an approach with decorators.
I am exposing a decorator called
custom_before_request
which will take two arguments:1.
path
- url route at which the user wants to execute the custom before request code2.
method
- the HTTP verb at which the user to execute the custom code at the specified url pathAfter this, when the decorator is applied on a user defined function, I save these three parameters(
path
,method
, and thefunction
on which the decorator is applied) in a global double/nested dict calledbefore_request_funcs
in the form{'path1':{'method1': function_to_be_called_at_this_path_and_method}}
.In the hydrus backend I have declared a function called
before_request_callback
(which is decorated by flask'sbefore_request
decorator) which checks the globalbefore_request_funcs
dict for any function to be called by checking the path and method of the current request and then calls the appropriate function.Let me know what you think of this implementation and how it could be improved.
PS:
app.py
and not been imported from any other file is to avoid the circular dependency issues in flask at the prototype stage.I will fix this issue once the prototype is accepted
related to #404
To test the feature locally:
python3 app.py
http://localhost:8080/api/MessageCollection
endpoint and observe the console output in your terminal.http://localhost:8080/api/MessageCollection
endpoint with appropriate body such asand observe the console output.
Checklist
Description
Change logs