How to publish an existing API on WSO2 ESB - api

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:
Logging the API calls
Messaging/ forking calls based on a criteria
Centralize all API calls authentication model
Is it possible to just run ESB server to achieve this function?
Thanks in Advance!!

Setting up a proxy API, this can only be done via
adding API option under main->service-bus->APIs
Give the API a custom name, which is the identity on WSO2 ESB.
Give the context which is your custom resource.
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

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

Related

Shopify Webhook integrate with mule

I have created REST API for POST HTTP and import it to Mule applications then deploy it to CloudHub and used that URL in Shopify Webhook then trying to get data but unable to get data from postman...
Is this a correct way to use Webhook in Mule applications...
Since Mule runtime doesn't has a concept of webhooks there is not a correct or incorrect way to use them. Mule applications can listen to HTTP requests. If another system sends an HTTP request to the correct URL that the Mule application is listening it should work. To the Mule application it doesn't matter if it is coming from a webhook, another application, Postman or whatever HTTP client implementation.

How to add header key to swagger editor in wso2 esb

I want to deploy my rest API to wso2 ESB. I am adding my API URL to the wso2 ESB swagger URL with the header authorization key. But I am not to add a header in the wso2 swagger URL. Here I am sending my code syntax,
Could anybody fix my problem?
<api xmlns="http://ws.apache.org/ns/synapse" name="meter" context="/Ls" hostname="localhost" version="1.0.0.0" version-type="url" publishSwagger="file:http://172.27.100.27:8000>
<resource methods="GET"/>
</api>

Mule API AutoDiscovery vs Mule API GatewayProxy

When should we use API Proxy against API AutoDiscovery. After implementing both, I found AutoDiscovery can also apply policies, analytics which API Gateway does, only thing is I cannot use a different url if using AutoDiscovery. Main advantage of API Proxy would be if my Gateway application and Mule Implementation Project is in different subnet, so if we are my Gateway server is compromised, no one can get to my implementation network.
But if both interface and implementation is in the same network, and purpose is just to call a REST Endpoint, should we not go with API AutoDiscovery.
Problems with Mule API Gateway Proxy
No defined way of Exception Handling, if we are not able to reach the Implementation Server.
No defined way of moving the Proxy Application across environments (CI/CD)
Extra HTTP Hops, can be acceptable if the above 2 issues have a defined way
Mule API AutoDiscovery
Since this is in the Mule Application, standard Exception Handling.
CI/CD is defined as it is the Mule Implementation Project.
No Extra HTTP Hop.
Only thing here is, we cannot change the implementation URL, that is only tightly coupled thing.
Can someone provide insight on when should we go for API Gateway vs AutoDiscovery. Also currently is there a way of doing Exception Handling in API Gateway Project and also CI / CD ?
API Autodiscovery is required if you plan to apply/unapply a policy to a particular endpoint, and/or take advantage of usage statistics in the context of API Platform. Api Autodiscovery is kind of metadata that links a HTTP(s) listener to its counterpart API version on API Manager.
For example:
<api-platform-gw:api id="api.basic.path" apiName="My API" version="1.0.0" flowRef="basic.path">
</api-platform-gw:api>
<flow name="basic.path">
<http:listener config-ref="a.http.config" />
<set-payload value="Endpoint successfully called." />
</flow>
Autogenerated Mule Proxies do have autodiscovery defined. You can also develop your own project and define the corresponding autodiscovery either by using the Studio UI, or handling the XML config directly.
The proxies are mean to be used in the case that your implementation backend is not a Mule application (for example, an existing REST based API hosted in a Tomcat server). You can enrich the logic with custom exception handling among other things on the Mule side. If you'd like better exception handling on the implementation backend, you will have to implement it there.
If your implementation backend is a Mule based application, using a proxy is not required. For most use cases, adding the corresponding autodiscovery element in the configuration file will do the trick.

Setup Mule web server and REST to SOAP proxy

I'm new to Mule and am trying to setup a web server [in Mule] to "replace" an existing Java server - which simply proxies for a SOAP web service.
So:
Web client (js/html) requests a static resource
Mule Server must return the static resource
or
Web client uses Jquery Ajax (json) request with path starting with "api/"
Mule Server must forward the request to the Java server (to use the old API)
or
Web client uses Jquery Ajax request with path starting with "sapi/"
Mule Server must translate the request to XML and call the SOAP server (for new api calls)
I'm struggling to find a good starting point:
I've played with Ajax connectors (and end-points) and can get the static content served - but not sure where to go with the api calls (don't want to force the client app to use mule.js)
I've played with HTTP end points, and I can't get the static content served (implicit Content-Type issue)
Any help will be appreciated...
Use http:static-resource-handler to serve your static content: it should take care of the content types for you. See for more info: http://www.mulesoft.org/documentation/display/current/HTTP+Transport+Reference#HTTPTransportReference-ServingStaticContent%28sinceMule3.2%29
Forget about the Ajax connector, all you need is the HTTP connector. Bind one HTTP endpoint on api and the other on sapi.
When forwarding the request, be sure to propagate headers and, potentially, path extension after api/. See the example below to see how this is typically done.
<flow name="rawProxy">
<http:inbound-endpoint
address="http://localhost:${http.port}/rest-proxies/raw"
exchange-pattern="request-response" />
<copy-properties propertyName="*" />
<http:outbound-endpoint address="http://localhost:${http.port}/rest/#[message.inboundProperties['http.relative.path']]?#[message.inboundProperties['http.query.string']]"
exchange-pattern="request-response" />
<response>
<copy-properties propertyName="*" />
</response>
</flow>
If the SOAP API you're calling as a WSDL then generate a client for it and instead of transforming to XML, transform to the request object it expects.

WSO2 API Manager - can it convert REST requests to SOAP requests on the backend?

I'm exploring the use of the WSO2 API Manager for our legacy API, which is currently SOAP based. IDeally, I'd like to expose a RESTful interface to our customers and have API Manager convert that to a SOAP request that gets passed to our legacy system. Searching the WSO2 site, I see there's some way to do this using XSLT transformations, but only when using the WSo2 ESB product.
Is there a way to handle this transformation in the API Manager? How? If not, could I somehow take advantage of the ESB product and combine it with the API Manager product? Or is that overkill?
Thanks!
REST to SOAP conversion is a standout feature of the WSO2 ESB. To learn more about it look at the sample given at [1]. The Payload Factory Mediator used in this sample is a much newer type of mediator than the XSLT Mediator and is also more efficient in handling SOAP messages than XSLT Mediator.
The WSO2 API Manager is a platform for publishing, managing and governing APIs. The WSO2 API Manager is built using the componentalized Carbon framework, for which almost all components of the WSO2 ESB are utilized. Therefore technically all that can be done with the WSO2 ESB can be done by the WSO2 API Manager; however without the help of the GUI found in the WSO2 ESB; you will have to use the source view of the configuration which is xml based. But ofcourse to navigate around this obstacle you can always download the WSO2 ESB product (which is also free and open-source) and create all the necessary mediation sequences using the GUI and copy-n-paste the configuration from the WSO2 ESB to the WSO2 API Manager and you are done.
In my opinion it is the WSO2 ESB that you need. In your case I presume you just have one or a few SOAP APIs which you need to expose as REST APIs; you are looking more at the REST-SOAP conversion feature rather than the ability to manage hundreds of APIs. If you do not need the core functionalities of the API Manager such as publishing APIs, versioning, authenticating consumers, throttling based on policies, and monitoring API usage (for a complete list of features look at the product homepage at [2]), then you really do not want the API Manager. But if you have the API Management requirements you can go with WSO2 API Manager. I don't think you should go with the WSO2 API Manager just because you foresee some kind of API Management requirements coming ahead.
Using both the WSO2 ESB fronted by the WSO2 API Manager is also a solution. WSO2 even recommends this architecture if you are performing heavy mediation in the mediation layer. You can even start with the WSO2 ESB alone and later when the proper requirements come, decide to front it with the WSO2 API Manager. Fronting the WSO2 ESB with the WSO2 API Manager is a breeze.
[1] http://docs.wso2.org/wiki/display/ESB403/Sample+800+Introduction+to+REST+API
[2] http://wso2.com/products/api-manager/