This sample demonstrates and end to end pizza ordering scenario where we have back-end services deployed in WSO2 Application Server (AS) to which we create APIs in WSO2 API Manager. Then, we invoke those APIs using a Web application deployed in WSO2 AS.
- Download and install WSO2 Application Server. If you do this on the same server as the APIM, be sure to offset its port by 1 to avoid port conflict. Go to
<PRODUCT_HOME>/repository/conf/carbon.xmland change <Offset>1</Offset>. For more information, see
Building the SampleRun
mvn clean installcommand in
<APIM_HOME>/samples/PizzaShack/pizza-shack-apito build the sample files.
Executing the Sample
- Log in to the API Publisher (https://localhost:9443/publisher) and create the following APIs.
Delivery API API Name= pizzaShack Context = /pizzashack/delivery Version = 1.0.0 Production Endpoint URL=http://localhost:9765/pizzashack-api-1.0.0/api/delivery API Resources =Keep the default values Order API API Name= pizzashack-order Context = /pizzashack/order Version = 1.0.0 Production Endpoint URL=http://localhost:9765/pizzashack-api-1.0.0/api/order API Resources =Keep the default values Menu API API Name= pizzashack-menu Context = /pizzashack/menu Version = 1.0.0 Production Endpoint URL=http://localhost:9765/pizzashack-api-1.0.0/api/menu API Resources =Keep the default values
- Navigate to the Lifecycles tab of each API and promote them to PUBLISHED state. This will push the APIs to the Gateway and they will be available for subscription in the API Store.
- Log in to the API Store (https://localhost:9443/store) and click on each API created earlier. Next, subscribe to each of them using the default application.
- After subscription, a message appears. Choose Go to My Subscriptions.
- The Subscriptions page opens. Create a production key by clicking the Generate button associated with it. You also have the option to increase the default token validity period, which is 1 hour.
You get the access token, a consumer key and a consumer secret. Replace the consumer key and secret pair in
<APIM_HOME>/samples/PizzaShack/pizza-shack-web/src/main/webapp/WEB-INF/web.xmlwith the newly generated ones. For example,
You now have three APIs subscribed under an application and an access token to the application. Next, we deploy a Web application in the Application Server and use it to invoke the APIs.
Start WSO2 AS (https://localhost:9443+<offset>/console) and log into its management console. For instructions, see (If the AS documentation link doesn't load, please clear your browser cache and retry).
<APIM_HOME>/samples/PizzaShack/pizza-shack-api/target/pizzashack-api-1.0.0.warinto the Application Server.
After deploying, access the application using
http://localhost:9764/pizzashack. It opens the application in a Web browser.
- You can use this application to order pizza. Internally, the APIs get invoked when you use the application.