25 February 2016
No Prerequisite knowledge required
This article describes three different ways of creating an API using the API Manager platform. They are:
This article also describes how to consume an API.
As an example of creating an API manually from scratch, you can build an API, GenderChecker. The API takes a name as input and returns if the name belongs to a male or a female.
The server side of this API already exists, as shown below:
In the example, 'http://truefbfriends.com' is the endpoint, 'analysis' is a resource, and 'firstname’ is the parameter.
To create the API using API Manager:
Log in to the API Manager portal as publisher.
After you log in, click Create API on the left navigation panel. Click Create REST API.
Enter the details of the API. You can assign any meaningful name to the API. Specify the endpoint as 'http://truefbfriends.com'
Now move to the Resources section. The example API has only one resource, which you can add. Enter /analysis and choose GET method. To add the resource, click Add Resource. You can expand the resource by clicking on the green arrow.
Add the parameter firstname. The parameter is of type query.
To publish the API, click Publish.
Once the API is published, you can preview of the API. You can verify the details and if required, edit and re-publish the API.
To test this API, click Test this API on the left navigation panel. Expand the resource.
Enter the value of parameter firstname. Choose Produces. Here, there is a single option. And finally, click Run API Call. Once the API call is complete, you can see the result along with the response and request details.
The REST API is complete and is ready for use.
Swagger is a formal specification surrounded by a large ecosystem of tools, which includes everything from front-end user interfaces, low-level code libraries, and commercial API management solutions. The API Manager supports importing an API from Swagger 1.2 and Swagger 2.0..
To import a Swagger doc:
In the Create API page, click Import REST API from Swagger.
Enter the URL of the Swagger doc. In this example, use petstore’s swagger doc.
After clicking Import , the REST API is generated using this Swagger doc. Details like version, description, and so on are fetched from the Swagger doc.
In the Resources section, you can view all the resources of the Petstore Swagger doc.
To publish the API, click Publish.
Test the API.
The API imported from a Swagger doc is now ready for use.
In the API manager, you can also import REST services registered in any ColdFusion server. To register a ColdFusion server with the API Manager:
In ColdFusion administrator, you can enable discovery of rest services. In the settings page, enable the option.
Register a REST service. The service is a basic CFC that returns the current date.
Register the REST service in ColdFusion admin.
In the API Manager administrator, register the ColdFusion server.
In the API Manager portal’s Create API page, click Import REST API from ColdFusion. You can see a pop-up containing all registered ColdFusion servers and all registered REST services.
Import any REST service. You can see the resources.
Publish and test your API.
The ColdFusion REST service is ready for use via the API Manager.
Once you publish an API, consumers can consume it.
As a publisher, you can create an API. To subscribe to an API, switch to subscriber view.
Navigate to the API catalog to browse all publicly available APIs. Click on any API you want to subscribe.
Once you click an API, you can see all the details of the API. You can even try out the API before subscribing to it.
Go to the Subscribe section. Choose the application you want to subscribe Choose the SLA plan you want to subscribe to and finally click Subscribe. You can now use the application key to invoke the API.
In the next few articles, we will describe how to create REST API from SOAP, importing SOAP API, and other advanced features of API Manager.