#Tech Note 1: How to publish an API
This is a step-by-step guide explaining how to register and describe an API, add it to the newly created product, and publish it to the Web.
In order to add an API you must either sign in or register first. See the Tech Note on sign up and registration for more information.
-
Sign into your account.
-
Select the APIs menu option on the left and click on the add API button.
-
The Add new API popup window will be displayed.
-
Provide values for the three fields (all required) on the Add new API popup window.
- Web API title provides a unique and descriptive name for the API. It is displayed in many places on the developer and administrative portals.
- Web service URL references HTTP service implementing the API. Apiphany platform will forward API requests to this address.
- Web API URL suffix is appended to the base URL. Base URL is common for all APIs hosted on the Apiphany platform by the API publisher. It can be viewed under the last input box. Apiphany platform distinguishes APIs by their suffix and therefore it must be unique for every API for a given publisher.
-
Once you have successfully made all of your entries click Save.
-
The settings section allows you to verify and edit the information you just entered.
-
You can optionally configure HTTP Basic Authentication for the web service implementing the API by checking the Enable Authentication checkbox and entering credentials.
-
Select your API by clicking on the APIs link in the menu, or, if you were in the process of creating an API then select operations:
-
Click the add operation button to add a new operation. The New operation window will be displayed and the Signature tab will be selected by default.
-
Specify HTTP method by placing cursor in the HTTP method input and selecting one of HTTP methods from the drop down list.
-
Define the URI template by typing in a URL fragment consisting of one or more URL path segments and zero or more query string parameters. URI template, appended to the base URL of the API, identifies a single HTTP operation. It may contain one or more named variable parts that are identified by curly braces. These variable parts are called template parameters and are dynamically assigned values extracted from the request's URL when the request is being processed by the Apiphany platform.
-
Optionally, specify the Rewrite URI template. Template parameters from the URI template should be used in the rewrite template. URL of the incoming operation request will be converted into a URL that would be forwarded to the web service that implements the API according to the URL - rewrite URL mapping. The following example shows how content type encoded as path segment in the web service can be provided as a query parameter in the API published via APiphany using the URI templates.
URI template:
/orders?format={contentType}
Rewrite URI template:
/{contentType}/orders
Request URL
.../orders?format=xml
is mapped to.../xml/orders
-
Enter a descriptive name for the operation in the Display name text box.
-
Operation description can be specified as plain text or HTML in the Description text box.
Response caching reduces latency perceived by the API consumers, lowers bandwidth consumption and decreases the load on the HTTP web service implementing the API. Note that comprehensive caching settings are available via the Policy page.
-
To easily and quickly enable caching for the operation, select the Caching tab and check the Enable checkbox.
-
In the Duration text box, change the time period during which cached responses remain fresh and are served from cache. Default value is 3600 second or 1 hour.
-
Optionally, enter specific query string parameters and/or HTTP headers to be used in computing cache key values in the Vary by string parameters and Vary by headers text boxes respectively. When none specified, full request URL and the following HTTP header values are used in cache key generation:
Accept
andAccept-Charset
.
Operation parameters are managed on the Parameters tab. Parameters specified in the URL Template on the Signature tab are added automatically and can be changed only by editing the URL template. Additional parameters can be entered manually.
To add a new query parameter, click add query parameter and enter the following information:
-
Name - parameter name.
-
Description - a brief description of the parameter (optional).
-
Type - parameter type, selected in the drop down.
-
Values - values that can be assigned to this parameter. One of the values can be marked as default (optional).
-
Required - make the parameter mandatory by checking the checkbox.
If the operation allows (e.g. PUT, POST) and requires a body you may provide an example of it in all of the supported representation formats (e.g. json, XML).
-
Switch to the Body tab.
-
Click add representation, start typing desired content type name (e.g.
application/json
) and then select it in the drop down. -
Paste request body example in the selected format into the text box.
-
Add description (optional).
It is a good practice to provide examples of responses for all status codes that the operation may produce. Each status code may have more than one response body example, one for each of the supported content types. For instance, to add an example of 200 OK
response perform the following steps:
-
Click on add response, start typing desired status code (e.g.
200 OK
in the text box, then select it in the drop down; The Code 200 tab is created and selected. -
Click add representation start typing desired content type name (e.g.
application/json
) and then select it in the drop down. -
Paste request body example in the selected format into the text box.
-
Add description (optional).
Do not forget to click Save button to persist the changes.
Please provide feedback or request assistance by sending an email to support@apiphany.com.