[Django]-Using Curl and Django Rest Framework in Terminal

3👍

After much deliberation, I resulted to a double-dose of coffee and got the proper way to implement the POST calls with JWT authentication. There is one caveat in that I had to put single quotes around the protected url to make a successful POST with the record persisting to the database. I also opted for not passing the data in JSON format as Key Value pairs since the JSON renderer will handle it.

For anyone else who encounters the same problem the syntax that worked is:

curl -H "Authorization: JWT YourToken" -d "field=value&field=value" 'http://127.0.0.1:8000/protected_url'

2👍

Did you try the format specified i the official documentation:

curl -X GET http://127.0.0.1:8000/api/example/ -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'

Leave a comment