WSO2 API Manager is a complete solution for publishing APIs, creating and managing a developer community and for routing API traffic in a scalable manner. It leverages the integration, security and governance components from the WSO2 Enterprise Service Bus, WSO2 Identity Server, and WSO2 Governance Registry. In addition, as it is powered by the WSO2 Business Activity Monitor (BAM), the WSO2 API Manager is ready for massively scalable deployments immediately.
...
- Open the API Publisher (
https://<hostname>:9443/publisher)
and log in asapicreator
if you haven't done so already. - Click the
PhoneVerification
API to open it and then click the Edit link right next to the API's name. This opens the API in its edit mode. - Click the Edit Swagger Definition button.
When the Swagger definition of the API opens, document the
PhoneNumber
andLicenseKey
parameters that you added to theGET
method at the time the API was created.navigate to the GET method, add two parameters to it asPhoneNumber
andLicenseKey
and document their descriptions. The code is given below:Anchor this step this step Code Block parameters: - description: Request Body name: body allowMultiple: false required: true type: string paramType: body - description: "Give the phone number to be validated" name: PhoneNumber type: string required: "True" paramType: query - description: "Give the license key. If you don't have any, enter 0" name: LicenseKey type: string required: "True" paramType: query
- Click Save once the changes are done. In a later section, we will see how these parameters appear to subscribers in the API Console of the API Store.
Versioning the API
Let's create a new version of this API.
- Log in to the API Publisher as
apicreator
if you are not logged in already. - Click on the
PhoneVerification
API and then the Copy button that appears in its Overview tab. Give a new version number (e.g., 2.0.0) and click Done.
Tip Tip: The Default Version option means that you make this version the default in a group of different versions of the API. A default API can be invoked without specifying the version number in the URL. For example, if you mark http://host:port/youtube/2.0 as the default version when the API has 1.0 and 3.0 versions as well, requests made to http://host:port/youtube/ get automatically routed to version 2.0.
If you mark any version of an API as the default, you get two API URLs in its Overview page in the API Store. One URL is with the version and the other is without. You can invoke a default version using both URLs.
If you mark an unpublished API as the default, the previous default, published API will still be used as the default until the new default API is published (or prototyped).
A new version of the API is created. It is a duplication of all the original API, including its documentation. The PhoneVerification 2.0.0
API is now ready to be published. This is typically done by a user in the publisher
role.
...
- Log in to the API Publisher as
apipublisher
that you created earlier in this guide. - Click on the
PhoneVerification
API version 2.0.0. Note that you now see a tab by the name Lifecycle in the API Publisher UI. - Go to the Lifecycle tab and select the state as
PUBLISHED
from the drop-down list.
The three checkboxes mean the following:- Propagate Changes to API Gateway: Used to define an API proxy in the API Gateway runtime component, allowing the API to be exposed to the consumers via the API Gateway. If this option is left unselected, the API metadata will not change and you will have to manually configure the API Gateway according to the information published in the API Store.
- Deprecate Old Versions: If selected, any prior versions of the API that are published will be set to the DEPRECATED state automatically.
- Require Re-Subscription: Invalidates current user subscriptions, forcing users to subscribe again.
- You have now deprecated an older version of an API and published a new version. Go back to the API Store and (
https://<hostname>:9443/store)
using your browser and note that thePhoneVerification 12.0.0
is not visible under the APIs menu because it is deprecated. You can see thePhoneVerification 2.0.0
API.
...
Subscribing to the API
You subscribe to APIs using the API Store Web application.
- Open the API Store (
https://<hostname>:9443/store)
using your browser. The API you published earlier is available in the API Store. Self sign up to the API Store using the Sign-up link.
After subscriptionsigning up, log in to the API Store and click the API that you published earlier (
PhoneVerification 2.0.0
).Note that you can now see the subscription
option inoptions on the right hand side of the UI
after logging in. Select the default application and
Bronze
tier, and click Subscribe.Applications
An application is a logical collection of one or more APIs, and is required when subscribing to an API. You can subscribe to multiple APIs using the same application. Instead of using the default application, you can also create your own by selecting the New Application... option in the above drop-down list or by going to the My Applications menu in the top menu bar.
- Once the subscription is successful, go to My Subscriptions page.
- In the My Subscriptions page, click the Generate buttons to generate production and sandbox access tokens and consumer key/secret pairs for the API.
- Once the subscription is successful, choose to go to the My Subscriptions page.
In the My Subscriptions page, click the Generate buttons to generate access tokens that you need to invoke the API.
Tip Tip: You can set a token validity period in the given text box. By default, it is set to one hour. If you set a minus value (e.g., -1), the token will never expire.
Invoking the API
To Let's invoke an API, you can use the integrated Swagger interactive documentation support (or any other simple REST client application or curl).
...
the API using the integrated Swagger-based API Console.
Click the APIs menu in the API Store and then click on the API that you want to invoke. When the API opens, go to its API Console tab.
Note the changes you did in the Swagger definition earlier displayed on the console. For example, expand the GET method and see the two Expand the GET method of the resource
CheckPhoneNumber
. Note the parameters that you added :
Let's invoke this API using the API Console.On the API Console, give in this step now appearing with their descriptions in the console.
Give sample values to the
PhoneNumber
andLicenseKey
and click Try it Out to invoke the API.Tip Tip: If you cannot invoke the API's HTTPS endpoint (causes the SSLPeerUnverified exception), it could be because the security certificate issued by the server is not trusted by your browser. To resolve this issue, access the HTTPS endpoint directly from your browser and accept the security certificate.
Note the response for the API invocation. As we used a valid phone number in this example, the response is valid.
You have invoked an API using the Swagger API consoleConsole.
Monitoring APIs and viewing statistics
...