I have my django server running in a ssh client (ubuntu) but I want to test the api's in the local window machine. How could I achieve that?
CodePudding user response:
If your web application is hosted ( have domain name like http://www.stackoverflow.com) use the url in your postman.
If your webapp not yet deployed in some webserver ( apacahe, nginx gunicorn, etc)
run the django application publicly in the server IP as follows
python manage.py runserver 0.0.0.0:8000 // make sure port 8000 is open or use an open port.
Also find the IP address of your ubuntu using the following command ( in the shell)
ifconfig
Use the ip-address you got in the postman (windows)
eg: if the IP address got is 90.101.111.25,
API endpoint: api/user/
method : POST
In postman client
use the url: 90.101.111.25/api/user/
select method : POST
Next you need to provide the Authorization ( to make sure only guanine users access your API).
Choose Authorization tab in postman, and select the Authorization ( Digest Auth, Basic, Token) your web app supports.
If you go with Token Authentication, find the the token for the (one of the )user created, and use it in postman.
Select Headers and add the following
key: Authorization
value: Token:<space>the-token-generated-by-django-in-the-db
Check the following to implement token based authentication in django( django-rest).
https://www.django-rest-framework.org/api-guide/authentication/