API creation is the process of linking an existing backend API implementation to the API Publisher so that you can manage and monitor the API's lifecycle, documentation, security, community, and subscriptions. Alternatively, you can provide the API implementation in-line in the API Publisher itself.
Click the following topics for a description of the concepts that you need to know when creating an API:
- Sign in to the WSO2 API Publisher.
https://<hostname>:9443/publisher (ex: https://localhost:9443/publisher).
Use admin as username and password. - In the APIS menu, click Add New API.
- Select Design New REST API and click Start Creating.
Give the information in the table below and click Add to add the resource.
Field Sample value Name PhoneVerification Context phoneverify
Tip: You can define the API's version as a parameter of its context by adding the
{version}
into the context. For example,{version}/phoneverify
. The API Manager assigns the actual version of the API to the{version}
parameter internally. For example,https://localhost:8243/1.0.0/phoneverify
. Note that the version appears before the context, allowing you to group your APIs based on the versions.Version 1.0.0 Visibility Public Resources URL pattern CheckPhoneNumber
Request types GET, POST
After you add the resource, click it's
GET
method to expand it. Update the value for Produces asapplication/xml
and the value for Consumes asapplication/json
.In the resource definition, we define the MIME types. Consumes refers to the MIME type of request accepted by the backend service and Produces refers to the MIME type of response produced by the backend service which you define as the endpoint of the API.
Next, add the following parameters. You use these parameters to invoke the API using our integrated API Console, which is explained in later tutorials.
Parameter Name Description Parameter Type Data Type Required PhoneNumber
Give the phone number to be validated Query String True LicenseKey
Give the license key as 0 for testing purpose Query String True Once done, click Next: Implement > .
Alternatively, click Save to save all the changes made to the API. You can come back later to edit it further by selecting the API and clicking on Edit. For details about the states of the API see Manage the API Lifecycle.The following parameter types can be defined according to the resource parameters you add.
Parameter Type Description query
Contains the fields added as part of the invocation URL that holds the data to be used to call the backend service. header
Contains the case-sensitive names followed by a colon (:) and then by its value which carries additional information with the request which defines the operating parameters of the transaction. formData
Contains a property list of attribute names and values which includes in the body of the message. body
An arbitrary amount of data of any type which sends with a POST message You can use the following Data type categories, supported by swagger.
Click the Managed API option.
The Implement tab opens. Enter the information in the table below.
Field Sample value Endpoint type HTTP/REST endpoint Production endpoint This sample service has two operations as
CheckPhoneNumber
andCheckPhoneNumbers
. Let's useCheckPhoneNumber
here.
http://ws.cdyne.com/phoneverify/phoneverify.asmxTo verify the URL, click the Test button next to it.
Sandbox endpoint This sample service has two operations as
CheckPhoneNumber
andCheckPhoneNumbers
. Let's useCheckPhoneNumber
here.
http://ws.cdyne.com/phoneverify/phoneverify.asmxTo verify the URL, click the Test button next to it.
Load balanced and fail over endpoints
In this sample load balanced and failover endpoint types are not selected. Load balanced endpoints are used to route incoming requests in round robbin manner. And fail over endpoints are specified to connect to in case of a failure. This also happen in round robbin manner. Please refer Working with Endpoints for more info
You can deploy your API as a Prototyped API in the Implement tab. A prototyped API is usually a mock implementation made public in order to get feedback about its usability. You can implement it Inline or by specifing an endpoint.
Users can invoke the API without a subscription after publishing the API to the Store. For more information refer Deploy and Test as a Prototype
Click Next: Manage > and enter the information in the table below.
Field Sample value Description Transports HTTP and HTTPS The transport protocol on which the API is exposed. Both HTTP and HTTPS transports are selected by default. If you want to limit API availability to only one transport (e.g., HTTPS), un-check the other transport.
You can only try out HTTPS based APIs via the API Console, because the API Store runs on HTTPS.
Subscription Tiers Select all The API can be available at different levels of service. They allow you to limit the number of successful hits to an API during a given period of time. - Click Save & Publish.
This publishes the API that you just created to the API Store so that subscribers can use it. You have created an API.
You can save partially complete or completed APIs without publishing it. Select the API and click on the Lifecycle tab to manage the API Lifecycle.