SlideShare a Scribd company logo
1 of 14
Rest Services In Mule
By,
Harish
Rest Full Webservice
● A web service is a collection of open protocols and standards used for
exchanging data between applications or systems
● Web services based on REST Architecture are known as RESTful
Web Services. These web services use HTTP methods to implement
the concept of REST architecture.
● A RESTful web service usually defines a URI (Uniform Resource
Identifier), which is a service that provides resource representation
such as JSON and a set of HTTP Methods.
HTTP Methods:
● The following HTTP methods are most commonly used in a
REST based architecture.
>GET − Provides a read only access to a resource.
>PUT − Used to update the existing resource.
>DELETE − Used to remove a resource.
>POST − Used to update an existing resource or create a new
resource.
REST service in MULE:
● In the context of web services, this generally means that
RESTful web services communicate via pure HTTP using
XML or JSON to encapsulate the data and metadata.
Publishing/Implementing a Rest Service: Two ways
1) APIkit
- APIkit can create an API based on a RAML (RESTful API
Modeling Language) API definition and produces a Mule
application with an HTTP endpoint, exception strategies
2) REST component:
- Use a REST API to publish an external RESTful web service.
- A REST component publishes a RESTful web service via
JAX-RS annotations and using Jersey by specifying the REST
component class.
Consuming a REST service:
To consume a REST API using Mule, use one of the following
techniques:
● Configure an HTTP connector to send requests to, and accept
responses from an API from within your Mule application.
● Build a connector using Anypoint Connector DevKit to perform
operations against the API.
Rest Component
● Mule hosts RESTful web services using Jersey, which is a
JAX-RS (JSR-311) implementation.
● JAX-RS is a specification that provides a series of annotations
and classes that make it possible to build RESTful services
● Using the annotations present in JAX-RS we can create unique
signatures(unique URI) for every type of request.
Annotations:
● @GET - Annotate your Get request methods with @GET
Eg: @GET
public String getHTML() {
...
}
● @Produces:specifies the type of output this method (or web
service) will produce
Eg:@GET
@Produces("application/xml")
public Contact getXML() {
...
}
● @Path: specify the URL path on which this method will be
invoked.
Eg: @GET
@Produces("application/xml")
@Path("xml/{firstName}")
public Contact getXML() {
...
● @PathParam-We can bind REST-style URL parameters to
method arguments using @PathParam annotation as shown
below.
Eg:
@GET
@Produces("application/xml")
@Path("xml/{firstName}")
public Contact getXML(@PathParam("firstName") String
firstName) {
Contact contact =
contactService.findByFirstName(firstName);
return contact;
}
● @QueryParam- Request parameters in query string can be
accessed using @QueryParam annotation as shown below.
Eg:
@GET
@Produces("application/json")
@Path("json/companyList")
public CompanyList getJSON(@QueryParam("start") int start,
@QueryParam("limit") int limit) {
CompanyList list = new
CompanyList(companyService.listCompanies(start, limit));
return list;
}
● @POST -Annotate POST request methods with @POST.
● @PUT-Annotate PUT request methods with @PUT
● @DELETE- Annotate DELETE request methods with
@DELETE.
● @Consumes-The @Consumes annotation is used to specify the
MIME media types a REST resource can consume.
Eg:
@PUT
@Consumes("application/json")
@Produces("application/json")
@Path("{contactId}")
public RestResponse<Contact> update(Contact contact) {
...
}
NOTE: used for POST and PUT operations.
Rest-Client:
● RESTClient is a simple application for talking to RESTful
web services.
● It is designed to fill a gap in existing offerings by offering
support for GET/POST/PUT/DELETE, making it a useful
tool when exploring RESTful web services which use a
wider range of HTTP verbs.
● RESTClient aims to fill this gap by allowing you to enter
*any* URL and POST/PUT/DELETE to it, you can move
data around more easily.
● By providing a simple user interface for copy pasting data,
you can fetch data from one source, copy it, change your
URL and post the data to another source.
Creating REST Clients
Rest Client in mule
● Step1: Create a rest service
- this rest service should be available for consuming it
● Step2:Consume the created rest service by creating a rest client
- write a java class for creating a rest client.
- using invoke you can call the rest client created.
Dynamic Endpoints:
● An outbound endpoint can also be dynamic. This means that the
endpoint’s URI is the value of an expression, which is
evaluated just before a message is sent to it.
● This allows the target of a message to be determined by its
contents or the value of any message property.
Dynamic endpoints can use either of the endpoint formats shown
above.
● <outbound-endpoint
address="smtp://user:secret@#[message.outboundProperties['h
ost']]"/>
● <jms:outbound-endpoint host="localhost"
queue="#[app.registry['defaultJmsQueue']]"/>
Thank You!!

More Related Content

What's hot

What's hot (16)

MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher
 
Mule batch
Mule batchMule batch
Mule batch
 
Mapping and listing with mule
Mapping and listing with muleMapping and listing with mule
Mapping and listing with mule
 
Mapping and listing in mule
Mapping and listing in muleMapping and listing in mule
Mapping and listing in mule
 
Mule enricher component
Mule enricher component Mule enricher component
Mule enricher component
 
Node js crash course session 3
Node js crash course   session 3Node js crash course   session 3
Node js crash course session 3
 
Mule parsing with json
Mule parsing with jsonMule parsing with json
Mule parsing with json
 
Automated testing web services - part 1
Automated testing web services - part 1Automated testing web services - part 1
Automated testing web services - part 1
 
Mule new jdbc component
Mule new jdbc componentMule new jdbc component
Mule new jdbc component
 
Mule: JSON to Object
Mule: JSON to ObjectMule: JSON to Object
Mule: JSON to Object
 
Servlet session 7
Servlet   session 7Servlet   session 7
Servlet session 7
 
Mule parsing with json part2
Mule parsing with json part2Mule parsing with json part2
Mule parsing with json part2
 
Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in mule
 
Encrypting/Decrypting mule
Encrypting/Decrypting  muleEncrypting/Decrypting  mule
Encrypting/Decrypting mule
 
Mule esb
Mule esbMule esb
Mule esb
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 

Similar to Rest service in mule

RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8Gajendra Sharma
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.pptKGSCSEPSGCT
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHPAndru Weir
 
Day1 : web service basics
Day1 :  web service basics Day1 :  web service basics
Day1 : web service basics Testing World
 
53 hui homework2
53 hui homework253 hui homework2
53 hui homework2huis89
 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET Journal
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Gaurav Bhardwaj
 
Secc tutorials development and deployment of rest web services in java_v2.0
Secc tutorials development and deployment of rest web services in java_v2.0Secc tutorials development and deployment of rest web services in java_v2.0
Secc tutorials development and deployment of rest web services in java_v2.0Aravindharamanan S
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State TransferPeter R. Egli
 
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonMulti Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonJoshua Long
 

Similar to Rest service in mule (20)

Rest web services
Rest web servicesRest web services
Rest web services
 
RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8
 
REST and RESTful Services
REST and RESTful ServicesREST and RESTful Services
REST and RESTful Services
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
Mule soft ppt 3
Mule soft ppt  3Mule soft ppt  3
Mule soft ppt 3
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.ppt
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHP
 
Day1 : web service basics
Day1 :  web service basics Day1 :  web service basics
Day1 : web service basics
 
53 hui homework2
53 hui homework253 hui homework2
53 hui homework2
 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce Site
 
ExpressJS and REST API.pptx
ExpressJS and REST API.pptxExpressJS and REST API.pptx
ExpressJS and REST API.pptx
 
Rest api design
Rest api designRest api design
Rest api design
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle
 
Secc tutorials development and deployment of rest web services in java_v2.0
Secc tutorials development and deployment of rest web services in java_v2.0Secc tutorials development and deployment of rest web services in java_v2.0
Secc tutorials development and deployment of rest web services in java_v2.0
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State Transfer
 
Rest web service
Rest web serviceRest web service
Rest web service
 
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonMulti Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
 
API Testing Basics.pptx
API Testing Basics.pptxAPI Testing Basics.pptx
API Testing Basics.pptx
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
Angularjs & REST
Angularjs & RESTAngularjs & REST
Angularjs & REST
 

More from Harish43

Cache scope and strategy
Cache scope and strategy Cache scope and strategy
Cache scope and strategy Harish43
 
Mule management console installation steps
Mule management console installation stepsMule management console installation steps
Mule management console installation stepsHarish43
 
Java components in mule
Java components in muleJava components in mule
Java components in muleHarish43
 
Queues and Mule Transport Mechanisms
Queues and Mule Transport MechanismsQueues and Mule Transport Mechanisms
Queues and Mule Transport MechanismsHarish43
 
Clustering concepts
Clustering conceptsClustering concepts
Clustering conceptsHarish43
 
Batch processing
Batch processingBatch processing
Batch processingHarish43
 
Batch processing
Batch processingBatch processing
Batch processingHarish43
 

More from Harish43 (7)

Cache scope and strategy
Cache scope and strategy Cache scope and strategy
Cache scope and strategy
 
Mule management console installation steps
Mule management console installation stepsMule management console installation steps
Mule management console installation steps
 
Java components in mule
Java components in muleJava components in mule
Java components in mule
 
Queues and Mule Transport Mechanisms
Queues and Mule Transport MechanismsQueues and Mule Transport Mechanisms
Queues and Mule Transport Mechanisms
 
Clustering concepts
Clustering conceptsClustering concepts
Clustering concepts
 
Batch processing
Batch processingBatch processing
Batch processing
 
Batch processing
Batch processingBatch processing
Batch processing
 

Recently uploaded

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Recently uploaded (20)

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Rest service in mule

  • 1. Rest Services In Mule By, Harish
  • 2. Rest Full Webservice ● A web service is a collection of open protocols and standards used for exchanging data between applications or systems ● Web services based on REST Architecture are known as RESTful Web Services. These web services use HTTP methods to implement the concept of REST architecture. ● A RESTful web service usually defines a URI (Uniform Resource Identifier), which is a service that provides resource representation such as JSON and a set of HTTP Methods.
  • 3. HTTP Methods: ● The following HTTP methods are most commonly used in a REST based architecture. >GET − Provides a read only access to a resource. >PUT − Used to update the existing resource. >DELETE − Used to remove a resource. >POST − Used to update an existing resource or create a new resource.
  • 4. REST service in MULE: ● In the context of web services, this generally means that RESTful web services communicate via pure HTTP using XML or JSON to encapsulate the data and metadata. Publishing/Implementing a Rest Service: Two ways 1) APIkit - APIkit can create an API based on a RAML (RESTful API Modeling Language) API definition and produces a Mule application with an HTTP endpoint, exception strategies 2) REST component: - Use a REST API to publish an external RESTful web service. - A REST component publishes a RESTful web service via JAX-RS annotations and using Jersey by specifying the REST component class.
  • 5. Consuming a REST service: To consume a REST API using Mule, use one of the following techniques: ● Configure an HTTP connector to send requests to, and accept responses from an API from within your Mule application. ● Build a connector using Anypoint Connector DevKit to perform operations against the API.
  • 6. Rest Component ● Mule hosts RESTful web services using Jersey, which is a JAX-RS (JSR-311) implementation. ● JAX-RS is a specification that provides a series of annotations and classes that make it possible to build RESTful services ● Using the annotations present in JAX-RS we can create unique signatures(unique URI) for every type of request. Annotations: ● @GET - Annotate your Get request methods with @GET Eg: @GET public String getHTML() { ... }
  • 7. ● @Produces:specifies the type of output this method (or web service) will produce Eg:@GET @Produces("application/xml") public Contact getXML() { ... } ● @Path: specify the URL path on which this method will be invoked. Eg: @GET @Produces("application/xml") @Path("xml/{firstName}") public Contact getXML() { ...
  • 8. ● @PathParam-We can bind REST-style URL parameters to method arguments using @PathParam annotation as shown below. Eg: @GET @Produces("application/xml") @Path("xml/{firstName}") public Contact getXML(@PathParam("firstName") String firstName) { Contact contact = contactService.findByFirstName(firstName); return contact; }
  • 9. ● @QueryParam- Request parameters in query string can be accessed using @QueryParam annotation as shown below. Eg: @GET @Produces("application/json") @Path("json/companyList") public CompanyList getJSON(@QueryParam("start") int start, @QueryParam("limit") int limit) { CompanyList list = new CompanyList(companyService.listCompanies(start, limit)); return list; } ● @POST -Annotate POST request methods with @POST. ● @PUT-Annotate PUT request methods with @PUT
  • 10. ● @DELETE- Annotate DELETE request methods with @DELETE. ● @Consumes-The @Consumes annotation is used to specify the MIME media types a REST resource can consume. Eg: @PUT @Consumes("application/json") @Produces("application/json") @Path("{contactId}") public RestResponse<Contact> update(Contact contact) { ... } NOTE: used for POST and PUT operations.
  • 11. Rest-Client: ● RESTClient is a simple application for talking to RESTful web services. ● It is designed to fill a gap in existing offerings by offering support for GET/POST/PUT/DELETE, making it a useful tool when exploring RESTful web services which use a wider range of HTTP verbs. ● RESTClient aims to fill this gap by allowing you to enter *any* URL and POST/PUT/DELETE to it, you can move data around more easily. ● By providing a simple user interface for copy pasting data, you can fetch data from one source, copy it, change your URL and post the data to another source. Creating REST Clients
  • 12. Rest Client in mule ● Step1: Create a rest service - this rest service should be available for consuming it ● Step2:Consume the created rest service by creating a rest client - write a java class for creating a rest client. - using invoke you can call the rest client created. Dynamic Endpoints: ● An outbound endpoint can also be dynamic. This means that the endpoint’s URI is the value of an expression, which is evaluated just before a message is sent to it. ● This allows the target of a message to be determined by its contents or the value of any message property.
  • 13. Dynamic endpoints can use either of the endpoint formats shown above. ● <outbound-endpoint address="smtp://user:secret@#[message.outboundProperties['h ost']]"/> ● <jms:outbound-endpoint host="localhost" queue="#[app.registry['defaultJmsQueue']]"/>