Encode
It signifies the MIME type of the content details in the response / request-body / argument.
Possible Locations
Attributes
Name | Type | Description |
---|---|---|
type required |
String | Type of the content. Refer here for sample encode types. |
Sample
JSON
Let us assume that we want the response body content encoded in JSON for trips resource. So you have to write the encode for the <response> as,
copy
<content>
<encode type="application/json" />
<structure>
<property name="trips" type ="collections">
<structure>
<property name="trip_name" type="string"/>
<property name="destination" type="string"/>
<property name="start_time" type="datetime"/>
<property name="end_time" type="datetime"/>
<property name="no_of_days" type="string"/>
</structure>
</property>
</structure>
</content>
Multi-part form data
Consider that in the destinations resource, we want to use form data encode type for <request-body>. Following are the details of the request body,
copy
- destination_name: Accepts only String values.
- image: Accepts only png files.
- The file name should contain only alphabets and a maximum of two files can be uploaded.
- Each file size should fall between 500 to 1000 bytes.
Now, write the request body as shown here.
copy
<request-body>
<content>
<encode type="multipart/form-data" />
<structure>
<property name="destination_name" type="string"/>
<property name="image" type="file" length="2">
<file-meta overall-size="2000">
<extension name="png" size="500,1000"/>
<file-name regex="^[a-zA-Z]+$"/>
</file-meta>
</property>
</structure>
</content>
</request-body>
Last Updated 2025-05-30 16:54:59 +0530 IST
Yes
No
Send your feedback to us
Skip
Submit