Reputation: 43027
I am following the labkit of the WSO2 Enterprise Integrator Developer Advanced course: https://wso2.com/training/enterprise-integrator-developer-advanced#request_training_enroll
and I have a doubt about the different between the concept of API and PROXY.
In this labkit there is an example related how to build a custom connector (the question is not strictly related to the connector topic).
In the example it first create and deploy a custom connector, then create and use this custom connector into this proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="googlebooks_listVolume"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="searchQuery"
expression="json-eval($.searchQuery)"/>
<googlebooks.listVolume>
<searchQuery>{$ctx:searchQuery}</searchQuery>
</googlebooks.listVolume>
<respond/>
</inSequence>
<outSequence>
<log/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
It worked fine and my connector is correctly called. But I am asking what is the exact difference between a PROXY like this and an API.
I read this: Difference between Proxy Service and API Service in wso2 Esb
Ok...using the API I can define multiple resources performing different CRUD operation while with a proxy I have a single entry point. The fact is that given this, there seems to be only one difference in comfort:
I need multiple CRUD operation? I implement an API. I need a single isolated operation? I implement a proxy.
But I think that there must also be other...
I know that APIs are based on REST concept. I also read that proxy is used to expose SOAP web service.
This last assertion is not so clear for me. To call the previous PROXY (implementing something like a WS) I do:
curl -v -X POST -d "{"searchQuery":"rabbit"}" -H "Content-Type: application/json" http://localhost:8280//services/googlebooks_listVolume
So it seems not to me a SOAP request because I am passing a JSON object containing my parameter that is used by this web service.
This is also not a pure REST web service, but I think that definitively it is not a SOAP service (that from what I know use a WSDL XML message.
So, what am I missing?
Upvotes: 3
Views: 1150
Reputation: 559
The main difference is same as what you mentioned. Proxy service is basically a SOAP service with its own WSDL file. APIs are considered RESTful services with resources mapping to HTTP verbs.
So how you could invoke a proxy using the above given curl command and how it worked?
The reason is the Content-Type
header that you are sending with your curl request. WSO2 EI or WSO2 ESB understands various content type headers and will read the content on the format specified (JSON
in this case) and then pass it to the underlying message mediation engine. Even though the server accepts this as a JSON
message, when the message is passed to the mediation engine (which does all the message mediation related work), it goes as a soap message underneath. So actually at the level of mediation engine, the proxy service will still receive a soap message but at transport level, we can send any support content types. This conversion is not visible to the user who is invoking the proxy service. So this is the reason that you could send a JSON
message to a SOAP
based proxy service.
Upvotes: 4