Now, we will use the HTTPie command or its curl equivalents to compose and send HTTP requests to the API. We will use JSON for the requests that require additional data. Remember that you can perform the same tasks with your favorite GUI-based tool or with the browsable API.
First, we will compose and send an HTTP request to create a new game category. Remember that we used the browsable API to create a game category named '3D RPG'
.
http POST :8000/game-categories/ name='2D mobile arcade'
The following is the equivalent curl
command:
curl -iX POST -H "Content-Type: application/json" -d '{"name":"2D mobile arcade"}' :8000/game-categories/
The preceding command will compose and send a POST
HTTP request with the specified JSON key-value pair. The request specifies /game-categories/
, and therefore, it will match '^game-categories/$'
and run the post
method for the views.GameCategoryList
class-based view. Remember that the method is defined in the ListCreateAPIView...