Uploading data
APIs can also be used to upload encoded content to a server such as application/json
for content in JSON format and multipart/form-data
for uploading files.
Templating is enabled on every content type.
Sync header's content type
Content type can be set on the Body
tab and automatically be replaced on the header. For this, there should be a Content-Type header with value {{ ctx.auto() }}
.
Content type
None
In order to send no body use the None
Content-Type. This special content type will not be sent on headers if it's value is {{ ctx.auto() }}
.
JSON, XML or other text-based content
Or more complex rendering
Form types
Form types are supported under:
multipart/form-data
application/x-www-form-urlencoded
Uploading a file
Set the content type to multipart/form-data
.
{{ ctx.load_file('my_file.txt') }}
The mime type is automatically inferred to change it, use the parameter mime_type
.
{{ ctx.load_file('my_file.txt', mime_type='text/plain') }}
Custom types
It's possible to write a custom tab on the Body tab. For this Content-Type header with value {{ ctx.auto() }}
.