Forms

Submitting forms is very similar to sending JSON requests. Often the onlydifference is in adding the —form, -f option, which ensures thatdata fields are serialized as, and Content-Type is set to,application/x-www-form-urlencoded; charset=utf-8. It is possible to makeform data the implicit content type instead of JSONvia the config file.

Regular forms

  1. $ http --form POST api.example.org/person/1 name='John Smith'
  1. POST /person/1 HTTP/1.1
  2. Content-Type: application/x-www-form-urlencoded; charset=utf-8
  3.  
  4. name=John+Smith

File upload forms

If one or more file fields is present, the serialization and content type ismultipart/form-data:

  1. $ http -f POST example.com/jobs name='John Smith' [email protected]~/Documents/cv.pdf

The request above is the same as if the following HTML form weresubmitted:

  1. <form enctype="multipart/form-data" method="post" action="http://example.com/jobs">
  2. <input type="text" name="name" />
  3. <input type="file" name="cv" />
  4. </form>

Note that @ is used to simulate a file upload form field, whereas[email protected] just embeds the file content as a regular text field value.