Monday, August 21, 2017

Creating APIs - Enterprise Service Bus

This page describes how you can create an API that allows URL parameters to be sent directly into the ESB. 

Goto wso2 developer Studio. 

01 . Create ESB Solution Project 
Click Developer Studio -> Open Dashboard -> Click ESB Solution Project 

ESB Project Name is  TestAPI


Remove Create Registry Resources Project and Create Connector Exporter Project. Only tick Create Composite Application Project. Then click Finish.

 02. Create REST API 

Right click on created project(Left side)

New =>REST API =>Create A New API Artifact 


Enter bellow parameters to text fields 









You can see created API in leftside





















Select Source code

<?xml version="1.0" encoding="UTF-8"?>
<api context="/service" hostname="localhost" name="urlParameterAPI" port="8280" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence/>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>


Then Change it like bellow code

<?xml version="1.0" encoding="UTF-8"?>
<api context="/service" hostname="localhost" name="urlParameterAPI" port="8280" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
             <log level="full">
                <property expression="get-property('username')"                  name="====USERNAME===="/>
            </log>
        </inSequence/>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>


Now its ok.

http://localhost:8280/service?username=Priyantha_Samaraweera



No comments:

Post a Comment