Adding and Editing Responses
A method must contain at least one response definition. A default response is added for each method in a resource. It uses the default response object for all HTTP codes that are not covered individually by the specification.
Click the method that you want to add response for and click Response.
Adding a Response
To add a response, complete these steps:
- In the Response Content Type section, select a response content type from the following options:
- application/json: the response content must be in JSON format. By default, this option is selected.
- application/xml: the response content must be in XML format.
Click Add to add a response.
- In the HTTP status code field, enter a unique status code. The HTTP status codes are used to indicate the response status of the executed operation.
- Enter a description for the entered status code.
Click next to Headers to add a response header:
- In the Name field, enter a header name.
- From the data type list, select a data type for the response header. By default, the data type is
- (Optional) Select the array check box if the response header is array.
- (Optional) In the Description field, enter a description for the added response header.
- (Optional) In the Default value field, enter a default value.
There are three methods to add the response schema:
You can model your schema from sample JSON data, and API Modeler will automatically generate a corresponding JSON schema object type.
Enter sample JSON data for your response in the Provide Sample Data box. This can be a JSON object or JSON array. The data will be validated as you type it, and a message in the lower left will indicate if the sample data is valid.
After entering valid sample data, click Generate Schema. The schema editor page will appear, with your sample data converted into a schema in the schema editor box.
To directly enter a complete JSON schema, click Input Schema. The schema editor page will appear, with a blank schema box. Enter your JSON schema in the box.
To use an existing schema, click Input Schema. The schema editor page will appear. Enter the name of the existing schema in the schema name box. The schema box will then be filled with the existing schema you selected. The scope of the existing schemas is within the same API specification.
If you modeled your schema or entered a complete schema, enter a unique name in the schema name box.
Note: If you enter an existing name, and choose this name in the auto-search results in the schema name box, the existing schema will be extracted and replace the schema you just modeled. if you enter an existing name and click Save without choosing the name from the list, the new schema will overwrite the existing schema under the name.
You can make further changes to the complete schema in the schema box, if required.
- Select a response schema from the following options:
- String: the response content can be any string.
- Reference: the request content must conform to the referenced JSON schema. This will be selected if you have entered or modeled a schema.
- None: no response content.
Select the array check box if the response body is an array of a string, or an array of the JSON object conforming to the schema referenced.
You can click Generate Schema from Sample Data to return to the Edit Response page with the Provide Sample Data box visible. This enables you to start over and enter new sample data. Note that the new generated schema will overwrite the existing schema. You must confirm that you wish to do this.
- Click Save when you are finished.
Editing a Response
To edit an added response, click the response card; To remove a defined response, move the mouse pointer over the response and click .
You can drag the response card to change the position of the added response. By default, the response cards are placed from the small HTTP status code to the large.