lundi 17 septembre 2018

How would I design my backend in Python for REST apis?

I am staring to develop a system which I will divide in two parts. A front-end with Angular and a Backend with Python (I will have to include machine learning and I am more familiar with it in py)

My biggest question now is what would be the best practices to separate the files and methods with a backend in Python. I've seen it done with Java and Node and I found they completely different.

So, as pure python doesn't ask for any pattern in order to run, I wanted to see what I could do to make it as professional as it can be (this is a side project I am doing in my work).

Right now I am separating my files like that:

Backend
   |_ server
        |_controllers
               |_ __init__.py
                  metrics.py  : has the functions that will proccess data from the queries and return to the api
        |_dbconfig
               |_ __init__.py : creates sqlalchemy engine/pooling
                  mssql.py    : has methods like "runSelect", "runUpdate"...
        |_models
               |_ __init__.py 
                  metrics.py  : has methods like "getAll" and "getAllByApi" that calls the mssql functions and contains all the queries
        |_routes
               |_ __init__.py
                  metrics.py  : calls the controller methods and handles the requests
    __init__.py
    run.py                    : starts the server

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire