Open app-generator opened 2 years ago
You can now test api. but implementation of view for api is TODO. to test api:
git clone https://github.com/app-generator/priv-dynamic-api-flask.git
cd priv-dynamic-api-flask/
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
export FLASK_APP=run.py
export FLASK_ENV=development
flask run
test crud is same as django project.
the base endpoint is: /api/model_name
for example send GET request to /api/books
, to get all books.
to add new model:
apps/dyn_api/models.py
apps/config.py
DYNAMIC_API
in this syntax (for example after adding City model):
DYNAMIC_API = {
'books': 'Book',
'cities' : 'City',
'endpoint': 'model name',
}
Code refactored @Mortrest Please update - Changes:
auth_middlewere
helper moved inside dyn_api
P.S. sorry if my changes caused merges on yr side
Hello @Mortrest
Please update. Changes:
/
at the end is usedRegressions:
request.form
(previously) was request.json
A possible patch might be to use both readers as below:
data = request.form
if not data:
data = request.json
{
"Authorization": "token {token_value}"
}
is the usual syntax for sending tokens. But we adapt the code with the changes you gave.
/api/register
and give username, password and email.Ty :)
Hello guys!
Codebase updated (better error checking + fix the edit item in API_VIEW page)
One question @Mortrest. Might be a silly one.
How the Authorization
token is pulled in JS files used in API_VIEW
page?
I don't see the injection from the backend in Jinja files.
Ty!
Hi @app-generator
After successful login, the Authorization token is stored in localStorage
.
https://github.com/app-generator/priv-devtool-flask-dynamic-api/blob/dd76eec73f9f745a62d8d16f6fef352d4e875804/apps/templates/accounts/login.html#L113
in API_VIEW
the token gets from localStorage
. Then it is used.
https://github.com/app-generator/priv-devtool-flask-dynamic-api/blob/dd76eec73f9f745a62d8d16f6fef352d4e875804/apps/templates/home/api-sample.html#L74
Nice. really nice ... 🚀🚀
Hello @Mortrest
Please drop here a message once the project can be tested. Also, please add here the complete usage instructions from cloning the project to the full usage of the dynamic API.
Ty