Content
It holds the details regarding the body of response / request / argument.
Possible Locations
Child Elements
- Encode required
- Error
- Path Config
- Structure or Structure Group or Composite Structure Groups or Stream required
- Example recurrent
- The <path-config> at the content level is given higher priority, allowing configuration of different data extraction paths for distinct content. In contrast, the path config declared at the <resource-config> level is generic and will be applied to all content, holding the lowest priority.
- The <error> provided at the content level is given the higher priority as it enables you to define different conditions for various <response>. Whereas, the error added at <operation> level is generic to all the responses under the particular operation and is given the lowest priority.
Attributes
Name | Type | Description |
---|---|---|
name required |
String | Name of the content. |
visibility | String (enum) | Decides who can view and use the element. The possible values are internal, private, public. The default value is public. |
The attribute name is mandatory only when content is a child element of <components>.
Samples
Stream
Imagine that we want to create a response content for file download. Following are the details of the file,
copyMaximum allowed size of the file: 5000 Maximum number of files that can be downloaded: 1 File format: pdf
Now write file download content for the trips resource as,
copy<response name="success" status="200"> <content> <encode type="application/pdf" /> <structure> <stream size="5000"/> </structure> </content> </response>
Path Config
In the trips resource, we want to build a request body with the following details.
copyrequest body: { "trips": [ { "trip_name":"Spring Break - John Doe", "destination": "Bali", "start_time": "2023-11-13T17:30:00", "end_time": "2023-11-17T22:30:00", "no_of_days": 4 } ] }
copy- The 'trips' key will be used to extract the resource data. - Error condition: The status key of response should be "invalid".
Here is how you should configure the content with <path-config> and <error>.
copy<request-body name="request_payload"> <content> <encode type="application/json" /> <error condition="$.status == invalid"/> <path-config data-extraction-path="$.trips"/> <structure name="data"> <property name="trips" type ="collections"> <structure> <property name="trip_name" type="string"/> <property name="trip_id" type="long_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> <example> <value> { "trips": [ { "trip_name":"Spring Break - John Doe", "trip_id":"5545974000000087501", "destination": "Bali", "start_time": "2023-11-13T17:30:00", "end_time": "2023-11-17T22:30:00", "no_of_days": 4 }, { "trip_name":"christmas Break - Diana Williams", "trip_id":"5545974000000087555", "destination": "London", "start_time": "2023-12-20T21:30:00", "end_time": "2023-12-28T09:30:00", "no_of_days": 7 } ] } </value> </example> </content> </request-body>
Structure Group
Consider that we want to build a content for response, in which three error structures have the same HTTP status code. Thus, you have to club them together using the structure group.
We have already declared those three structures in the <components>.
- INVALID_REQUEST_METHOD
- INVALID_DATA
- DUPLICATE_DATA
copy<components> <structure name="errorpattern" ref-name="error_pattern"> <property type="map"> <structure name="response" cases="InvalidValueInURLPath"> <property name="code" type="string" values="INVALID_URL_PATTERN" /> <property name="details" type="map" /> <property name="message" type="string" values="Please check if the URL trying to access is a correct one" /> <property name="status" type="string" values="error" /> </structure> </property> </structure> <structure name="INVALID_DATA" extend="error_pattern" cases="InvalidValue"> <property name="message" type="string" values="You have used an invalid page_token or the one generated by another user." /> <property name="code" type="string" values="INVALID_DATA" /> </structure> <structure name="INVALID_REQUEST_METHOD" extend="error_pattern"> <property name="code" type="string" values="INVALID_REQUEST_METHOD" /> <property name="message" type="string" values="The http request method type is not a valid one" /> </structure> <structure name="DUPLICATE_DATA" extend="error_pattern" cases="Unique"> <property name="code" type="string" values="DUPLICATE_DATA" /> <property name="message" type="string" values="Failed to add since a record with same name already exists" /> </structure> </components>
Now, write the content for this requirement as follows,
copy<response name="error" status="400"> <content> <encode type="application/json" /> <structure-group name="400errors" type="one-of"> <structure-ref name="INVALID_REQUEST_METHOD"/> <structure-ref name="INVALID_DATA"/> <structure-ref name="DUPLICATE_DATA"/> </structure-group> </content> </response>
Last Updated 2025-05-30 16:54:59 +0530 +0530
Yes
No
Send your feedback to us