I am doing simple app which has to connect to external REST api, get data in json and print it for the user. My questions are:
-
Where should I put/create a module which will connect to external REST api? I mean I could just write some code in views.py which connects to REST api and the passes the results to template but I want to separate it in some autonomic module which I could use in views.py like
myapimodule.get_devices()which for example will connect and get data from example.com/api/device/get. I tried python and django for first time today so I just want to know where u put (and how) such modules in django app? -
How I can connect to RESTAPI with django? I have for example username and password for http auth and address like example.com/api/device/get – what parts of django lib will allow me to use the restapi and retrieve data from it (in json format)?
There’s really no “right” answer. It just depends on what’s best for your needs.
To connect to an external REST API, take a look at the excellent Requests library.