Type: How-to and step-by-step tutorial
Tags: REST, HTTP, JSON
Product: webMethods Integration Server. Tried it with version 9.6
When to apply: You've got a flow service that needs to consume a REST service - whether it's RESTful or "not so RESTful".
This document explains how to consume a REST call by converting an Integration Server document to JSON and sending it by making an HTTP call.
Example repository: https://github.com/juanaltech/webmethodsRestConsumerExample
Summary of steps
Prerequisistes
Create a document type that defines the structure of the JSON content.
Steps
In the flow service that calls the REST service, add the following:
- Populate the content of document of the type created in the initial step
- Use the
pub.json:documentToJSONString
built-in service to convert the document to a JSON string - Use
pub.client:http
to make an HTTP request. The json string from the previous step needs to be mapped todata/string
. You'll also need to set values for fields such asurl
andmethod
. Finally, add the necessary headers for the request. You'd normally need to add: Content-Type
, with a value of the resource type for the request and, optionally, the encoding. This may beapplication/json; charset=UTF-8
in simple cases.Accept
, with a value of the expected resource type of the response. This may beapplication/json
in simple cases.
Step-by-step Example
In this simple example, I'll show you how to consume a hypothetical REST service in order to send information about a car.
You may grab the code from: https://github.com/juanaltech/webmethodsRestConsumerExample
You may grab the code from: https://github.com/juanaltech/webmethodsRestConsumerExample
Create package and folder
You may use use an existing package with a folder hierarchy. In our example, we'll create a new package package and a
restconsumer
folder. First, select New Package, type in the the package name, RestConsumerDemo
, and select OK. Next, right click on the containing package and select New Folder and create a new folder called restconsumer
.Create a document type
Right click on the
restconsumer
folder and select New Document Type. We'll assign it a name of Car
.
In the document type pane, right click on a blank space and select insert String to create a field named
make
. Repeat this step to create a field named model
.Create the flow service
Right click on the
restconsumer
folder and select New Flow Service. Type in consume
as the name and hit OK.
Right click on an empty spot in the Tree tab, select Insert, Map.
Make sure the pipeline view is visible and then drag the
Car
document type from the Package Navigator into the Pipeline Out
section in the pipeline view. This will create a new document of that type. Rename the document's name to car
.
In order to assign values to make and model, right click on the field and select "Set Value". We'll use "Volkswagen" and "Golf".
Add pub.json:documentToString service invocation
In order to add a new step in the service, right click on an empty spot in the Tree tab again and select Insert from the context menu and select
Invoke
. Navigate to the WmPublic
package, select the pub/json
folder and then select the documentToString
service.
Map the
car
document in pipeline in to the document field in documentToJsonString
by dragging one field onto the other - once you do that you'll see a black line connecting both fields. Notice a jsonString
value is created automatically in Pipeline Out.
Add pub.client:http invocation
Right click on an empty space in the Tree tab again. This time insert an invocation to pub.client:http from the public
WmPublic
package.
Now all the action happens in the the pipeline view. Assign all the values that are required. In this example, we'll assign the following:
url
: specify the URL to your resource. We'll assume the resource is available at http://localhost:8089/carsmethod
: we'll useput
in our example- Map the
jsonString
field to thedata/string
field in pub.client:http - Right click on the
headers
Service In field and to add headers with a type of String. We'll add two: Content-Type
, which will have a value assigned ofapplication/json; charset=UTF-8
Accept
, with a value ofapplication/json
Try it
You may now run the
consume
service by right clicking on it, selecting Run As and Run Flow Service. If you capture the request, you'll notice a string like this is sent in the body: {"make":"Volkswagen","model":"Golf"}
If you get a connection refused error, it's most likely because there's no service provider on the URL you specified. Once you make sure it's pointing to the right location, you should see a value of 200 on the response status code inside the results pane.
Recommendations
In order to provide robustness, a complete implementation should typically check the header's status (HTTP status code) to ensure the returned value falls in the range between 200 and 299.
When other values are returned, e.g., 500, your code should typically exit with a failure or throw an exception.
Excellent tutorial and very, very useful.
ReplyDeleteas an extra, you could add how to read a json response.
1. pub.string.bytesToString of Body/bytes
2. pub.json.jsonStringToDocument
Hi Federico,
DeleteDo you mean the two services which are mentioned for inbound JSON data?
I am working with 8.2 and can't upgrade to 9.6..I have a requirement to expose json end point to clitents. how do I do it?
ReplyDeleteHi n,
DeleteAt a fist look it seems that all that Juanal did with 9.8 can be done also with 8.2.
Except for the services documentToJSON and jsonToDocument. This services are not available in 8.2.
For the documentToJSON however, you can easily create a recursive JAVA service that transforms the IData into an JSON string.
Hi ,
ReplyDeleteI am facing issue wherein when I send data for DELETE operation, it does not go properly.
Hi n and Impailer
ReplyDeleteFor those using an older webMethods, such as 8.2, an option is to use the Tundra library (https://github.com/Permafrost/Tundra). It provides the tundra.json:emit service (https://github.com/Permafrost/Tundra/blob/master/SERVICES.md#tundrajsonemit), which generates a JSON representation of an IS document.
This comment has been removed by the author.
ReplyDeleteThanks Juanal, its very much useful.
ReplyDeleteHello..
ReplyDeletePlease, how Can I make a Json string with numeric fields, however withou "" character.
Something like this:
{"Name":"Ronaldo","Age":42,"Gender":"M"}
Take a look into Age field value, that is without "".
Thank you.
Ronaldo
Hello..
ReplyDeletePlease, how Can I make a Json string with numeric fields, however withou "" character.
Something like this:
{"Name":"Ronaldo","Age":42,"Gender":"M"}
Take a look into Age field value, that is without "".
Thank you.
Ronaldo
Nice Articles.
ReplyDeletewebMethods Developer Training in chennai | webMethods Online Training
Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingmulesoft online training
ReplyDeleteIt seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
ReplyDeleteJava training in Bangalore | Java training in Kalyan nagar
Java training in Bangalore | Java training in Jaya nagar
Selenium training in Chennai | Selenium training institute in Chennai | Selenium course in Chennai
Selenium training in Bangalore | Selenium training institute in Bangalore | Selenium course in Bangalore
I am really very happy to find this particular site. I just wanted to say thank you for this huge read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.
ReplyDeletepython interview questions and answers
python tutorials
python course institute in electronic city
When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.
ReplyDeleteAmazon Web Services Interview Questions And Answers | Best AWS interview questions 2018
Advanced Amazon Web Services Training in Chennai | Best AWS Training Institute in Chennai
Best AWS Training Institute in Pune | Best AWS Training Center in Pune
Best AWS Training Institute in Marathahalli | Advanced AWS Training in Marathahalli, Bangalore
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteJava training in Bangalore | Java training in Kalyan nagar
Java training in Bangalore | Java training in Kalyan nagar
Java training in Bangalore | Java training in Jaya nagar
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteBest Devops Training in pune
excel advanced excel training in bangalore
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteData Science training in rajaji nagar | Data Science Training in Bangalore
Data Science with Python training in chennai
Data Science training in electronic city
Data Science training in USA
Data science training in pune
Thank you for an additional great post. Exactly where else could anybody get that kind of facts in this kind of a ideal way of writing? I have a presentation next week, and I’m around the appear for this kind of data.
ReplyDeleteangularjs Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
angularjs-Training in velachery
angularjs-Training in pune
ReplyDeleteHello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
Advanced AWS Training in Marathahalli |No.1 AWS Training in Marathahalli
Best AWS Amazon Web Services Training Institute in Chennai | No.1 AWS Training Institutes for Solution Architect in Chennai | Advanced AWS Certification Training in Chennai
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeleterpa training in bangalore
best rpa training in bangalore
rpa training in pune
What will be the published url of REST service created above? I tried 2,3 urls but unable to call it from Postman. My Service is working on designer, i need published url so that some other system can call webmethods integration service.
ReplyDeleteKindly support
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on sharing!!.
ReplyDeleteandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me
ReplyDeleteweb designing training in chennai
web designing training in annanagar
digital marketing training in chennai
digital marketing training in annanagar
rpa training in chennai
rpa training in annanagar
tally training in chennai
tally training in annanagar
I am really very happy to find this particular site. I just wanted to say thank you for this huge read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.
ReplyDeleteweb designing training in chennai
web designing training in omr
digital marketing training in chennai
digital marketing training in omr
rpa training in chennai
rpa training in omr
tally training in chennai
tally training in omr
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site
ReplyDeleteWebmethods Training in Bangalore
Lakers Portland Odds (2021) - Casinoland 메리트카지노 메리트카지노 jeetwin jeetwin 66Golden Casino Review 2021 - Bonuses & Bonuses
ReplyDeletetitanium dog teeth implants and a new replacement for
ReplyDeleteThe brand new titanium dog teeth pad allows for the titanium spork removal stiletto titanium hammer of a razor blade from a razor blade. This is t fal titanium pan the best titanium flat iron only way you babylisspro nano titanium can do your nails.
Great post. keep sharing such a worthy information.
ReplyDeleteWeb Designing Course In Chennai
Sports Betting - Mapyro
ReplyDeleteBet the moneyline from 출장안마 1:25 PM to 11:00 PM. See more. 출장안마 MapYO Sportsbook features live odds, deccasino live streaming, 메이피로출장마사지 and detailed information. https://febcasino.com/review/merit-casino/
Best institute for Commerce students
ReplyDeletebest ca colleges in hyderabad
best mec inter colleges in hyderabad
best cec inter colleges in hyderabad
best cma colleges in hyderabad
best degree colleges in hyderabad
best cs colleges in hyderabad