APIs created in WSO2 API Manager have their own life cycle consisting of the following: a set of life cycle states, specific actions for each state transition, and a checklist of items before a state transition occurs. An API has a predefined life cycle consists of six states. This tutorial demonstrates how you can edit the default API lifecycle and customize it according to your requirements.
This capability is not available in WSO2 API Manager versions prior to 1.10.0.
Follow the steps below to add a new state to the default life cycle.
- Sign in to the API Publisher and click on the API that you created previously (e.g., PizzaShackAPI - 1.0.0).
- Click Lifecycle to view the current states available by default.
- Open the WSO2 API Manager Management Console: https://localhost:9443/carbon
- Navigate to Extensions > Configure > Lifecycles.
Click the View/Edit link corresponding to the default API LifeCycle.
The APILifeCycle configurations appear.
Update the API lifecycle definition.
Add a sample state to the API Lifecycle.
Copy and paste the following sample code in the file.
The sample REJECTED state is added between PUBLISHED and RETIRED. It uses the
Retirestate transition events to change to the consequent states. Custom checklist items are also given under
"checkItems", which are tasks to be done in a state transition. You can select/deselect these items in the management console.
The same execution class is used (
org.wso2.carbon.apimgt.impl.executors.APIExecutor) for all state transitions. However, you can plug your own execution code when modifying the life cycle configuration.
For example, if you want to add notifications for a specific state transition, you can plug your own custom execution class for that particular state in the API life cycle. Any changes are updated in the Lifecycle tab accordingly.
Add a new transition event under the PUBLISHED state, to show the state change to REJECTED.
- Make the transition event visible in API Publisher.
- Open the
Add the following code in the file. Note that the key value in the JSON pair should be lowercase.
- Open the
- Restart the WSO2 API Manager server.
- Re-open API Publisher and check the Lifecycle to see the changes.
Consider the following points when extending and customizing the API lifecycle XML configuration.
- Do not change the life cycle name since it needs to be engaged with the APIs dynamically.
- Make sure you keep the PUBLISHED and PROTOTYPED states as those two states will be used by API Publisher in the API creation wizard.
For more details on customizing the API lifecycle, see Extending the API Life Cycle.