CentraSite Documentation : Working with REST-based APIs : Creating a RESTful API from Scratch : Adding HTTP Method to REST API
Adding HTTP Method to REST API
The HTTP methods passed as part of an HTTP request tell the API what operation needs to be done with the addressed resource.
Pre-requisites
Understand the predefined HTTP methods and their known attributes. See the HTTP method definitions information to learn more about the common set of methods for HTTP.
Clients use HTTP methods to perform certain operations. Multiple methods exist - GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH, TRACE, and CONNECT.
Important:  
During virtualization of an API, CentraSite does not support the following HTTP methods: HEAD, OPTIONS, PATCH, TRACE, and CONNECT. This is because, when a virtual API is published to webMethods Mediator, at run-time, the HTTP methods GET, POST, PUT, DELETE are only supported.
Let us consider the following scenarios for our sample Phone Store API:
Resource URI
Supported HTTP Methods
Description
/phones
GET
List all phones.
/phones
POST
Creates a new phone with product code 412456.
/phones/412456
GET
Retrieves details of a phone whose product code is 412456.
/phones/412456
DELETE
Removes a phone whose product code is 412456.
/phones/412456?fields=(make,features, bodytype)
GET
Retrieves additional details (such as Brand, Features, Body Type) of a phone whose product code is 412456.
/phones/412456/make
GET
Identifies the brand of a phone whose product code is 412456.
/phones/search?q=(make,eq,apple)
GET
Retrieves a list of all phones whose brand is Apple.
/phones/412456?make=apple&features=3g
PUT
Updates a phone whose product code is 412456, brand is Apple, and also 3G compatible.
Resource methods can also use parameters to identify or pass additional information.
You can capture the sample requests and responses to facilitate clients easily interact with the resources of API.
You can set HTTP status codes to help client quickly and more easily understand the HTTP response messages.
In this task, you define the valid operations for the resources. In addition, you can define the resource representation formats and the samples to represent the HTTP requests and responses.
To add a HTTP method
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. Locate the resource you want to add HTTP methods.
5. Click the Add Method link.
6. In the Add Method dialog box, enter the following information in the fields provided:
In this field...
Do the following...
Name
Optional. Enter a name for the method.
Description
Optional. Enter descriptive information about the method.
HTTP Method
Select the HTTP operation you want to perform on the resource. (The drop-down list displays the list of supported HTTP methods.)
Request Content-Type
Select the content format for request message. (The drop-down list displays the list of supported content formats.)
Note:  
By default, this field shows an empty default value.
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 shows an empty default value.
Deprecated
Optional. Specify whether or not the REST method is deprecated.
Parameters - Add Parameter (link)
Optional. Specify one or more request parameters of the following types at the Method level:
*Query-String
*Header
*Form
Although CentraSite allows you to define parameters of the type "Form" at the Method level, these parameters are not supported at run-time. Only parameters of the type Query-String and Header are supported at run-time.
Note:  
You cannot add more than one parameter with the same name and the same type within the method.
a. Click the Add Parameter link to open the Add Parameter dialog.
b. In this dialog, you define input parameters at the Method level. To specify multiple parameters, click the Add Parameter link to add each new parameter.
The new parameter is added to the method. For a complete description of how to set up the request parameters, see Adding Parameter to REST API.
Requests - Add Request (link)
Optional. Specify one or more HTTP requests to the resources of the REST API. For a complete description of how to set up the HTTP requests, see Adding HTTP Request to REST API.
Responses - Add Response (link)
Optional. Specify one or more HTTP responses to the resources of the REST API. For a complete description of how to set up the HTTP responses, see Adding HTTP Response to REST API.
Sample Requests and Responses - Add Request and Response (link)
Optional. Write one or more sample requests to the resources of the REST API, and the corresponding sample responses from the API. For a complete description of how to expose the HTTP requests and response messages, see Adding Request and Response Messages to REST API.
7. Click the newly added method to view its details.
8. To further update the new method, mouse over the method, and then click the Edit icon. Repeat for each method that you want to modify.
9. To specify multiple methods, click the Add Method link to add each new method.
10. After you specify the value for all of the required fields, click the Save icon to save the changes.
Copyright © 2005-2015 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback