In Chapter 13, Creating API Views, when we composed and sent POST
and PUT
commands, we had to use the use the -H "Content-Type: application/json"
option to indicate curl to send the data specified after the -d
option as application/json
. We had to use this option because the default content-type in curl is application/x-www-form-urlencoded
.
Now, our RESTful Web Service goes beyond JSON and it can also parse application/x-www-form-urlencoded
and multipart/form-data
data specified in the POST
and PUT
requests. Hence, we can compose and send a POST
command that sends the data as application/x-www-form-urlencoded
.
We will compose and send an HTTP request to create a new toy. In this case, we will use the -f
option for HTTP.
This option serializes data items from the command line as form fields and sets the Content-Type
header key to the application/x-www-form-urlencoded
value. Run the next command:
http -f POST :8000/toys/ name="Ken in Rome" description="Ken...