Django REST Framework / Python / Uncategorized

API Contracts on Django REST API

Curl Request to verify API Contracts, on Django REST Framework

Request a particular file

API Contracts


domain/files/(id) : Fetch the specified file for download

curl example:

sys2@sys2-HP-Compaq-8100-Elite-SFF-PC:~$ curl –user vidya:root@123 http://127.0.0.1:8000/files/26/
{“url”:”http://127.0.0.1:8000/files/26/”,”file”:”http://127.0.0.1:8000/uploads/uploads/file1.csv”}

browser example: http://127.0.0.1:8000/files/26/


domain/files : Displays a list of files uploaded

curl example:

sys2@sys2-HP-Compaq-8100-Elite-SFF-PC:~$ curl –user vidya:roo.0.1:8000/files/
{“count”:2,”next”:null,”previous”:null,”results”:[{“url”:”http://127.0.0.1:8000/files/26/”,”file”:”http://127.0.0.1:8000/uploads/uploads/file1.csv”},{“url”:”http://127.0.0.1:8000/files/28/”,”file”:”http://127.0.0.1:8000/uploads/uploads/file2.csv”}]}

browser example: http://127.0.0.1:8000/files/


POST A FILE

curl example 1:

sys2@sys2-HP-Compaq-8100-Elite-SFF-PC:~$ curl –user vidya:root@123 ‘http://127.0.0.1:8000/files/’ -H ‘Host: 127.0.0.1:8000’  -H ‘Content-Type: multipart/form-data; -F “file=file11.csv”‘
{“count”:4,”next”:null,”previous”:null,”results”:[{“url”:”http://127.0.0.1:8000/files/26/”,”file”:”http://127.0.0.1:8000/uploads/uploads/file1.csv”},{“url”:”http://127.0.0.1:8000/files/28/”,”file”:”http://127.0.0.1:8000/uploads/uploads/file2.csv”},{“url”:”http://127.0.0.1:8000/files/29/”,”file”:”http://127.0.0.1:8000/uploads/uploads/file2_SDn3yjT.csv”},{“url”:”http://127.0.0.1:8000/files/30/”,”file”:”http://127.0.0.1:8000/uploads/uploads/file2_HsAHYWQ.csv”}]}sys2@sys2-HP-Compaq-8100-Elite-SFF-PC:~$

curl example 2:

sys2@sys2-HP-Compaq-8100-Elite-SFF-PC:~$ curl -X POST -H “Content-Type:multipart/form-data” -u vidya:root@123 -F “file=file11.csv;” http://localhost:8000/files/


https://github.com/kevinastone/django-api-rest-and-angular

Leave a Reply

Your email address will not be published. Required fields are marked *