user3173632
user3173632

Reputation: 17

How to publish an existing API on WSO2 ESB

I can't seem to find a simple article on how to publish an existing restAPI through WSO2 ESB as proxy.

I have an existing API which responds with either Json or XML output based on content-type on the header. I would like to publish this api through the WSO2 ESB as proxy. I don't think WSO2 Application server is needed in this case, as the rest api is running on its own app server.

API: http://somehost.com:8001/api/BusinessApi/GetContentTypes

Response:

[{"contentTypeID":1,"name":"Movies","isTop":true,"subLevels":1,"contentTypeIdBase":1},{"contentTypeID":2,"name":"TV Show","isTop":true,"subLevels":3,"contentTypeIdBase":4},{"contentTypeID":3,"name":"TV Season","isTop":false,"subLevels":2,"contentTypeIdBase":4},{"contentTypeID":4,"name":"TV Episode","isTop":false,"subLevels":1,"contentTypeIdBase":4},{"contentTypeID":5,"name":"Music Album","isTop":true,"subLevels":2,"contentTypeIdBase":6},{"contentTypeID":6,"name":"Music Track","isTop":false,"subLevels":1,"contentTypeIdBase":6},{"contentTypeID":7,"name":"Music Video","isTop":false,"subLevels":1,"contentTypeIdBase":7},{"contentTypeID":8,"name":"Book Set","isTop":false,"subLevels":1,"contentTypeIdBase":8},{"contentTypeID":9,"name":"Books","isTop":true,"subLevels":1,"contentTypeIdBase":9}]

The objective is to publish the api via WSO2 ESB and try to achieve the below actions:

  1. Logging the API calls
  2. Messaging/ forking calls based on a criteria
  3. Centralize all API calls authentication model
  4. Is it possible to just run ESB server to achieve this function?

Thanks in Advance!!

Upvotes: 0

Views: 761

Answers (2)

Amila Maharachchi
Amila Maharachchi

Reputation: 2149

With your approach, you have created an api in ESB, which passes the request to your backend api. During this you expect to log every api call and control authentication too. I didn't understand the forking requirement.

Have you tried WSO2 API Manager? It will allow you to make your api a managed api. i.e. You will be able to control access to your api via oauth tokens. You can log the api calls too (although its not a good thing to log every call due to performance reasons).

If you integrate it with WSO2 DAS, you will be able to see some useful stats too. This is the API Manager documentation.

https://docs.wso2.com/display/AM1100/WSO2+API+Manager+Documentation

Upvotes: 0

user3173632
user3173632

Reputation: 17

Setting up a proxy API, this can only be done via

  1. adding API option under main->service-bus->APIs
  2. Give the API a custom name, which is the identity on WSO2 ESB.
  3. Give the context which is your custom resource.
  4. go to the source view and add the below source

Begin of snippet

<api xmlns="http://ws.apache.org/ns/synapse" name="GetC" context="/api1">
   <resource methods="GET" url-mapping="/">
      <inSequence>
         <log/>
         <send>
            <endpoint>
               <address uri="http://somehost.com:8001/api/businessApi/GetContentTypes"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log/>
         <send/>
      </outSequence>
   </resource>
</api>

End of snippet

You should now be to access the api via ESB proxy url

Upvotes: 1

Related Questions