Reputation: 721
I have to create an API supplying some relevant information using Mule ESB. In order to do that, I need to communicate with some others API providers (Wikipedia API for example) toobtain information and craft the JSON response to return the required information.
PS: I use maven to manage my dependencies.
Do you have any ideas fom where to start or the dependencies/Mule components that can help? I'll be thankful
Upvotes: 1
Views: 146
Reputation: 16495
You can use options provided by Victor. Here some offical documentation:
Publishing and Consuming APIs with Mule
These options require an intermediate knowledge of the mule. Dont worry, if you dont have time, you can use all java frameworks with mule:
Publish Basic Rest API(assuming you do not use soap services):
Create flow with an http-listener + rest component + java entity.
Or create a rest service using spring and deploy it in tomcat for example and send request parameters to some jms queue. Create a jms receive component in mule. This receive parameters from queue and passing the data to the next component in order to create a json response and return to spring rest service.
Consume Rest service
For example. You could use apache client and create a maven project as library to be used or invoke inside java mule component:
public class MuleComponent {
public Object executeRestClient(Object muleMessage){
//based on apache client
MyRestClientLibrary client = MyRestClientLibrary ();
client.setUrl("http://wikipedia/rest/service/..");
Object someParameters = muleMessage.getProperty("someParameter"....
Object response = client.executeOperation01(someParameters);
return response;//data to be used by next component
}
}
This component could be used by any mule flow who needs to consume data from wikipedia service.
This could be a possible solution:
<rest-inbound> ->
[get request params] ->
[consume-external-service(rest apache client)]->
[get data from DB or another source] ->
[build json response] ->
<rest-outbound>
Regards.
Upvotes: 0
Reputation: 5115
To create your own API start with APIkit.
Then to consume rest you have two options, leverage the http connector and a RAML definition (only applicable if the api to be consumed is REST based) or create your own connector with devkit.
Upvotes: 2