Testing our API

We're now ready to test the API we've built. Let's fire up the server from the command line.

  1. python manage.py runserver

We can now access our API, both from the command-line, using tools like curl

  1. bash: curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/users/
  2. {
  3. "count": 2,
  4. "next": null,
  5. "previous": null,
  6. "results": [
  7. {
  8. "email": "admin@example.com",
  9. "groups": [],
  10. "url": "http://127.0.0.1:8000/users/1/",
  11. "username": "admin"
  12. },
  13. {
  14. "email": "tom@example.com",
  15. "groups": [ ],
  16. "url": "http://127.0.0.1:8000/users/2/",
  17. "username": "tom"
  18. }
  19. ]
  20. }

Or using the httpie, command line tool…

  1. bash: http -a admin:password123 http://127.0.0.1:8000/users/
  2. HTTP/1.1 200 OK
  3. ...
  4. {
  5. "count": 2,
  6. "next": null,
  7. "previous": null,
  8. "results": [
  9. {
  10. "email": "admin@example.com",
  11. "groups": [],
  12. "url": "http://localhost:8000/users/1/",
  13. "username": "paul"
  14. },
  15. {
  16. "email": "tom@example.com",
  17. "groups": [ ],
  18. "url": "http://127.0.0.1:8000/users/2/",
  19. "username": "tom"
  20. }
  21. ]
  22. }

Or directly through the browser, by going to the URL http://127.0.0.1:8000/users/

Quick start image

If you're working through the browser, make sure to login using the control in the top right corner.

Great, that was easy!

If you want to get a more in depth understanding of how REST framework fits together head on over to the tutorial, or start browsing the API guide.