SlideShare a Scribd company logo
How to use REST Component
15-12-2014
Abstract
• The main motto of this PPT is How to use REST
Component in our applications.
Introduction
• REST stands for Representational State
Transfer. REST exposes a much simpler
interface than SOAP. REST components are
bound with HTTP. So, if you are designing
an application to be used exclusively on the
Web, REST is a very good option. RESTful
applications simply rely on the built-in HTTP
security. A REST design is good for database-
driven applications and also when a client
wants quick integration.
SOAP Component POC:
Link: https://youtu.be/h-aJIjt9TcQ
How to do above POC using REST component?
Example
ArthematicOperations
a. Addition
b. Subtraction
c. Multiplication
How to use rest component
.mflow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd">
<flow name="RestComponentFlow1" doc:name="RestComponentFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8098" doc:name="HTTP"/>
<logger message="---Entered into the flow" level="INFO" doc:name="Logger"/>
<jersey:resources doc:name="REST">
<component class="com.ArthematicOperations"/>
</jersey:resources>
</flow>
</mule>
com.ArthematicOperations:
• package com;
• import javax.ws.rs.Consumes;
• import javax.ws.rs.POST;
• import javax.ws.rs.Path;
• import javax.ws.rs.Produces;
• import javax.ws.rs.core.MediaType;
• import org.codehaus.jackson.JsonNode;
• import org.codehaus.jettison.json.JSONObject;
• @Path("/")
• public class ArthematicOperations {
• @POST
• @Produces(MediaType.APPLICATION_JSON)
• @Consumes(MediaType.APPLICATION_JSON)
• @Path("Addition")
• public Object addition(JsonNode inputJSON) throws Exception {
• JSONObject jsonStatus = new JSONObject();
• jsonStatus.put("Result",(Integer.parseInt(inputJSON.get("Num1").getTextValue())+Integer.parseInt(inputJSON.get("Num2").getTextValue())));
• return jsonStatus.toString();
• }
• @POST
• @Consumes(MediaType.APPLICATION_JSON)
• @Produces(MediaType.APPLICATION_JSON)
• @Path("Subtraction")
• public Object subtraction(JsonNode inputJSON) throws Exception {JSONObject jsonStatus = new JSONObject();
• jsonStatus.put("Result",(Integer.parseInt(inputJSON.get("Num1").getTextValue())-Integer.parseInt(inputJSON.get("Num2").getTextValue())));
• return jsonStatus.toString();
• }
• @POST
• @Consumes(MediaType.APPLICATION_JSON)
• @Produces(MediaType.APPLICATION_JSON)
• @Path("Multiplication")
• public Object multiplication(JsonNode inputJSON) throws Exception {JSONObject jsonStatus = new JSONObject();
• jsonStatus.put("Result",(Integer.parseInt(inputJSON.get("Num1").getTextValue())*Integer.parseInt(inputJSON.get("Num2").getTextValue())));
• return jsonStatus.toString();
• }
• }
How to test this?
URLs
Addition: http://localhost:8098/Addition
Subtraction: http://localhost:8098/Subtraction
Multiplication:
http://localhost:8098/Multiplication
Trigger the methods:
1. Addition:
• Console:
INFO 2015-12-15 18:09:29,554 [main] org.mule.DefaultMuleContext:
**********************************************************************
* Application: RestComponent *
* OS encoding: Cp1252, Mule encoding: UTF-8 *
* *
* Agents Running: *
* Clustering Agent *
* JMX Agent *
**********************************************************************
INFO 2015-12-15 18:09:29,556 [main]
org.mule.module.launcher.MuleDeploymentService:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'RestComponent' +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2015-12-15 18:10:28,825
[[RestComponent].connector.http.mule.default.receiver.02]
org.mule.api.processor.LoggerMessageProcessor: ---Entered into the flow
References
• https://docs.mulesoft.com/mule-user-
guide/v/3.7/rest-component-reference

More Related Content

PPTX
Rest Component
PDF
2.2 Reliable Message Bus based on RocketMQ
PPTX
Intro To Selenium
PDF
MuleSoft Surat Virtual Meetup#25 - Anypoint Platform Features and Capabilitie...
PPTX
Load balancer in mule
PPTX
Client side performance analysis
PDF
4. Apache RocketMQ 5.0, embracing the Distributed Messaging Standard OpenMes...
PPTX
Mule esb soap_service
Rest Component
2.2 Reliable Message Bus based on RocketMQ
Intro To Selenium
MuleSoft Surat Virtual Meetup#25 - Anypoint Platform Features and Capabilitie...
Load balancer in mule
Client side performance analysis
4. Apache RocketMQ 5.0, embracing the Distributed Messaging Standard OpenMes...
Mule esb soap_service

What's hot (7)

PPTX
Basic example using until successful component
PDF
ITB2016 - Building ColdFusion RESTFul Services
PPTX
Migrando una app de angular.js a Blazor
PPTX
Mule soap
PPT
Anypoint connectorfor ibm as 400
PPTX
Webservice vm in mule
PPT
PHP and MySQL
Basic example using until successful component
ITB2016 - Building ColdFusion RESTFul Services
Migrando una app de angular.js a Blazor
Mule soap
Anypoint connectorfor ibm as 400
Webservice vm in mule
PHP and MySQL
Ad

Viewers also liked (15)

PPTX
Similar product analysis
PPTX
PPTX
NFPtweetup 8: RAFBF 1940 chronicle presentation
DOCX
Embedded training
PPTX
Using Intergenerational Approaches for Digital Inclusion
PPTX
Question 2 - How effective is the combination of your main product and ancill...
PPTX
Home remedies for burping (belching)
DOC
Desember 0002 copy
PPTX
Sesión 4
PPSX
Arteonline bcn emma
PPTX
Lavacow presentation
PPT
Te amo
PPTX
Age Awareness
PDF
#TorontoHR - How to achieve continuous feedback that drives results - Priya B...
PDF
Bosch, Jaipur
Similar product analysis
NFPtweetup 8: RAFBF 1940 chronicle presentation
Embedded training
Using Intergenerational Approaches for Digital Inclusion
Question 2 - How effective is the combination of your main product and ancill...
Home remedies for burping (belching)
Desember 0002 copy
Sesión 4
Arteonline bcn emma
Lavacow presentation
Te amo
Age Awareness
#TorontoHR - How to achieve continuous feedback that drives results - Priya B...
Bosch, Jaipur
Ad

Similar to How to use rest component (20)

PPTX
REST: So What's It All About? (SAP TechEd 2011, MOB107)
PDF
RESTful applications: The why and how by Maikel Mardjan
PDF
REST full API Design
PDF
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
PPTX
Introduction To REST
PDF
REST - What's It All About? (SAP TechEd 2012, CD110)
PDF
Hia 1691-using iib-to_support_api_economy
PPT
Web services - REST and SOAP
PDF
JavaEE6 my way
PDF
Introducing the Hub for Data Orchestration
PDF
Modern REST API design principles and rules.pdf
PDF
Modern REST API design principles and rules.pdf
PPTX
Rest applied
PDF
MuleSoft Online Meetup a Guide to RTF application deployment - October 2020
PDF
Talking to 25% of the web - In-depth report and analysis on the WordPress RES...
PDF
zendframework2 restful
PDF
Rest api best practices – comprehensive handbook
PDF
Checklist for progressive web app development
PPTX
Web Application Development using PHP and MySQL
PPTX
Overview of Rest Service and ASP.NET WEB API
REST: So What's It All About? (SAP TechEd 2011, MOB107)
RESTful applications: The why and how by Maikel Mardjan
REST full API Design
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
Introduction To REST
REST - What's It All About? (SAP TechEd 2012, CD110)
Hia 1691-using iib-to_support_api_economy
Web services - REST and SOAP
JavaEE6 my way
Introducing the Hub for Data Orchestration
Modern REST API design principles and rules.pdf
Modern REST API design principles and rules.pdf
Rest applied
MuleSoft Online Meetup a Guide to RTF application deployment - October 2020
Talking to 25% of the web - In-depth report and analysis on the WordPress RES...
zendframework2 restful
Rest api best practices – comprehensive handbook
Checklist for progressive web app development
Web Application Development using PHP and MySQL
Overview of Rest Service and ASP.NET WEB API

More from RaviRajuRamaKrishna (14)

PPTX
Mock component in munit
PPTX
Jms selector
PPTX
PPTX
Object store
PPTX
How to use splitter component
PPTX
How to use soap component
PPTX
How to use salesforce cloud connector
PPTX
How to use expression filter
PPTX
How to use wildcard filter
PPTX
How to use not filter
PPTX
How to use or filter
PPTX
How to use and filter
PPTX
How to use data mapper transformer
PPTX
How to use bean as datasource in database connector
Mock component in munit
Jms selector
Object store
How to use splitter component
How to use soap component
How to use salesforce cloud connector
How to use expression filter
How to use wildcard filter
How to use not filter
How to use or filter
How to use and filter
How to use data mapper transformer
How to use bean as datasource in database connector

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Lesson notes of climatology university.
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Pre independence Education in Inndia.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Basic Mud Logging Guide for educational purpose
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Institutional Correction lecture only . . .
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
FourierSeries-QuestionsWithAnswers(Part-A).pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Lesson notes of climatology university.
Microbial disease of the cardiovascular and lymphatic systems
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pre independence Education in Inndia.pdf
Renaissance Architecture: A Journey from Faith to Humanism
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Basic Mud Logging Guide for educational purpose
Sports Quiz easy sports quiz sports quiz
Microbial diseases, their pathogenesis and prophylaxis
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Institutional Correction lecture only . . .
Module 4: Burden of Disease Tutorial Slides S2 2025

How to use rest component

  • 1. How to use REST Component 15-12-2014
  • 2. Abstract • The main motto of this PPT is How to use REST Component in our applications.
  • 3. Introduction • REST stands for Representational State Transfer. REST exposes a much simpler interface than SOAP. REST components are bound with HTTP. So, if you are designing an application to be used exclusively on the Web, REST is a very good option. RESTful applications simply rely on the built-in HTTP security. A REST design is good for database- driven applications and also when a client wants quick integration.
  • 4. SOAP Component POC: Link: https://youtu.be/h-aJIjt9TcQ How to do above POC using REST component?
  • 7. .mflow <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd"> <flow name="RestComponentFlow1" doc:name="RestComponentFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8098" doc:name="HTTP"/> <logger message="---Entered into the flow" level="INFO" doc:name="Logger"/> <jersey:resources doc:name="REST"> <component class="com.ArthematicOperations"/> </jersey:resources> </flow> </mule>
  • 8. com.ArthematicOperations: • package com; • import javax.ws.rs.Consumes; • import javax.ws.rs.POST; • import javax.ws.rs.Path; • import javax.ws.rs.Produces; • import javax.ws.rs.core.MediaType; • import org.codehaus.jackson.JsonNode; • import org.codehaus.jettison.json.JSONObject; • @Path("/") • public class ArthematicOperations { • @POST • @Produces(MediaType.APPLICATION_JSON) • @Consumes(MediaType.APPLICATION_JSON) • @Path("Addition") • public Object addition(JsonNode inputJSON) throws Exception { • JSONObject jsonStatus = new JSONObject(); • jsonStatus.put("Result",(Integer.parseInt(inputJSON.get("Num1").getTextValue())+Integer.parseInt(inputJSON.get("Num2").getTextValue()))); • return jsonStatus.toString(); • } • @POST • @Consumes(MediaType.APPLICATION_JSON) • @Produces(MediaType.APPLICATION_JSON) • @Path("Subtraction") • public Object subtraction(JsonNode inputJSON) throws Exception {JSONObject jsonStatus = new JSONObject(); • jsonStatus.put("Result",(Integer.parseInt(inputJSON.get("Num1").getTextValue())-Integer.parseInt(inputJSON.get("Num2").getTextValue()))); • return jsonStatus.toString(); • } • @POST • @Consumes(MediaType.APPLICATION_JSON) • @Produces(MediaType.APPLICATION_JSON) • @Path("Multiplication") • public Object multiplication(JsonNode inputJSON) throws Exception {JSONObject jsonStatus = new JSONObject(); • jsonStatus.put("Result",(Integer.parseInt(inputJSON.get("Num1").getTextValue())*Integer.parseInt(inputJSON.get("Num2").getTextValue()))); • return jsonStatus.toString(); • } • }
  • 9. How to test this? URLs Addition: http://localhost:8098/Addition Subtraction: http://localhost:8098/Subtraction Multiplication: http://localhost:8098/Multiplication
  • 11. • Console: INFO 2015-12-15 18:09:29,554 [main] org.mule.DefaultMuleContext: ********************************************************************** * Application: RestComponent * * OS encoding: Cp1252, Mule encoding: UTF-8 * * * * Agents Running: * * Clustering Agent * * JMX Agent * ********************************************************************** INFO 2015-12-15 18:09:29,556 [main] org.mule.module.launcher.MuleDeploymentService: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Started app 'RestComponent' + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ INFO 2015-12-15 18:10:28,825 [[RestComponent].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: ---Entered into the flow