SOA Governance and API Management : Working with REST-based APIs : Creating a RESTful API from Scratch : Adding HTTP Response to REST API
Adding HTTP Response to REST API
A HTTP response indicates the success or failure of an API invocation.
Pre-requisites
HTTP/1.1 defines all the legal status codes. Examine these codes to determine which are appropriate for your API.
HTTP response status codes provide information about the status of a HTTP request. The HTTP specification defines several status codes that are typically understood by clients.
In this task, you define the valid responses for the HTTP requests. In addition, you can define the response representation formats, and the schemas and examples to represent the HTTP responses.
To add a HTTP response
1. Display the details page of the REST API (see Viewing the Details of a REST API for details).
2. In the actions bar for the API, click the Edit icon.
3. Select the Resource and Methods profile.
4. In the Add/Modify Method dialog box, expand the Responses section.
5. Click the Add Response link.
6. In the Add Response dialog box, enter the following information in the fields provided:
In this field...
Do the following...
Status Code
Select a HTTP response status code number.
Examples
*HTTP 200 OK
*HTTP 400 Bad Request
*HTTP Error 404 Not Found
*HTTP Error 500 Internal Server Error
Name
This is a label that you assign as a meaningful name for the HTTP response.
For example, you may call a HTTP 400 response as Validation Error, instead of the Bad Request.
Description
Optional. Enter a comment or descriptive information about the response.
Response Content-Type
Select the content format for response message. (The drop-down list displays the list of supported content formats.)
Note:  
By default, this field displays an empty default value.
Schema
Optional. Specify a HTTP response message (payload) using either XML schema or JSON schema.
Inline or External File
Specify whether the schema definition will be read from an inline text (the Inline option) or from an external file or URL (the External File option).
If you want to use an inline schema, specify the schema definition manually in the Inline text box.
If the schema definition you are uploading resides on the network, specify its URL.
If the schema definition resides in an external file, specify the file name. You can use the Browse button to navigate to the required folder.
Note:  
As a best practice, you should use the Inline option to include small number of data and use the External File option to include large number of data stored in an external file.
Example
Optional. Specify a HTTP response message (payload) using examples to show how a schema is used. An example is simply an XML code or JSON code.
Inline or External File
Specify whether the example will be read from an inline example code (the Inline option) or from an external file or URL (the External File option).
If you want to use an inline example, specify the example code manually in the Inline text box.
If the example definition you are uploading resides on the network, specify its URL.
If the example definition resides in an external file, specify the file name. You can use the Browse button to navigate to the required folder.
Note:  
As a best practice, you should use the Inline option to include small number of data and use the External File option to include large number of data stored in an external file.
Headers - Add Header (link)
Optional. Specify one or more headers that you want to include in the HTTP response.
Note:  
A header name must be unique within the response.
a. Click the Add Header link.
b. In the Add Header dialog box, specify the required fields.
7. To further update the new response, mouse over the response, and then click the Edit icon. Repeat for each response that you want to modify.
8. To specify multiple responses, click the Add Response link to add each new response.
9. If you need to delete a response, mouse over the response, and then click the Delete icon. Repeat for each response that you want to delete.
10. After you specify the value for all of the required fields, click the Save icon to save the changes.
Copyright © 2015- 2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback