app-generator / flask-dynamic-api

Flask Dynamic API - Developer Tool | AppSeed
https://appseed.us
Other
3 stars 0 forks source link

Project Status #2

Open app-generator opened 2 years ago

app-generator commented 2 years ago

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

Mortrest commented 2 years ago

You can now test api. but implementation of view for api is TODO. to test api:

  1. clone project: git clone https://github.com/app-generator/priv-dynamic-api-flask.git
  2. run the project after cd, source venv and export environment variables:
    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:

  1. go to apps/dyn_api/models.py
  2. define new model.
  3. go to apps/config.py
  4. add enpoint and defined model name to DYNAMIC_API in this syntax (for example after adding City model):
    DYNAMIC_API = {
    'books': 'Book',
    'cities' : 'City',
    'endpoint': 'model name',
    }
  5. test CRUD methods.
app-generator commented 2 years ago

Code refactored @Mortrest Please update - Changes:

P.S. sorry if my changes caused merges on yr side

app-generator commented 2 years ago

Hello @Mortrest

Please update. Changes:

Regressions:

A possible patch might be to use both readers as below:

data = request.form
if not data: 
  data = request.json  
Mortrest commented 2 years ago
app-generator commented 2 years ago

Ty :)

app-generator commented 2 years ago

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!

Mortrest commented 2 years ago

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

app-generator commented 2 years ago

Nice. really nice ... 🚀🚀