DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Surprisingly Simple Tools to Help You Smash API-First Approach
  • Breaking Up a Monolithic Database with Kong
  • Building REST API Backend Easily With Ballerina Language
  • Aggregating REST APIs Calls Using Apache Camel

Trending

  • Scalability 101: How to Build, Measure, and Improve It
  • Fixing Common Oracle Database Problems
  • Virtual Threads: A Game-Changer for Concurrency
  • Beyond Microservices: The Emerging Post-Monolith Architecture for 2025
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Design, Develop, Deploy and Manage a RESTful Application With MuleSoft

Design, Develop, Deploy and Manage a RESTful Application With MuleSoft

Learn how to create a RESTful application with MuleSoft from scratch based on two scenario.

By 
Sravan Lingam user avatar
Sravan Lingam
DZone Core CORE ·
Updated Aug. 03, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
12.1K Views

Join the DZone community and get the full member experience.

Join For Free

This article shows you how to design, develop, deploy, and manage a simple RESTful Application using MuleSoft.

Let us take a simple real-time scenario of how ATM works internally.

Scenario 1: /checkBalance?accountNum=12345&bankName=icici

When a user provides a valid account number and bank name, the API should result in the balance that is available. (Here we connect to Database to get details)

Scenario 2 : /withdrawBalance?accountNum=12345&bankName=icici&withDrawAmount=5000

When a user provides a valid account number, bank name and amount to be withdrawn, the API should result in the Total balance after deduction available. (Here we connect to Database to get details)

In both cases, we have to send Bad request if accountNumber is not exactly 5digits. And for now, let us have only 2 Banks icici and axis.

In scenario 2, if withDrawAmount is greater than the total balance available, return a statement saying Insufficient Funds.

Let us follow the following steps to build an API to achieve the scenarios.

Design

We have seen there is a scenario where we have certain validations regarding account number and bank name. To start off, we need to design a blueprint of our application which resembles the actual functionality. To design it, we use RAML (RESTful API Modeling Language).

RAML is a way of describing practically-RESTful APIs in a way that's highly readable by both humans and computers.

To make this happen, MuleSoft provides a space to Design - Anypoint Platform's Design Center.

Step1: To access Design Center go to http://anypoint.mulesoft.com/ GoTo DesignCenter. 

Step2: Click on Design Center and click on Create --> Create API Specification

Step3: Design your RAML.

YAML
 




x
79


 
1
#%RAML 1.0
2
 
          
3
title: BankDetails
4
 
          
5
version: 1.0
6
 
          
7
/checkBalance:
8
 
          
9
 get:
10
 
          
11
   queryParameters:
12
 
          
13
     accountNum:
14
 
          
15
       required: true
16
 
          
17
       maxLength: 5
18
 
          
19
       minLength: 5
20
 
          
21
     bankName:
22
 
          
23
       required: true
24
 
          
25
       enum: ['icici','axis']
26
 
          
27
   responses:
28
 
          
29
     200:
30
 
          
31
       body:
32
 
          
33
         application/json:
34
 
          
35
           example: |
36
 
          
37
             {"result":"your balance is 55000"}
38
 
          
39
 
          
40
 
          
41
 
          
42
/withDrawAmount:
43
 
          
44
 get:
45
 
          
46
   queryParameters:
47
 
          
48
     accountNum:
49
 
          
50
       required: true
51
 
          
52
       maxLength: 5
53
 
          
54
       minLength: 5
55
 
          
56
     bankName:
57
 
          
58
       required: true
59
 
          
60
       enum: ['icici','axis']
61
 
          
62
     amountToBeWithdrawn:
63
 
          
64
       required: true
65
 
          
66
 
          
67
 
          
68
 
          
69
   responses:
70
 
          
71
     200:
72
 
          
73
       body:
74
 
          
75
         application/json:
76
 
          
77
           example: |
78
 
          
79
             {'result':'your balance is 10000'}



Step 4: After designing your RAML, enable Mocking Service which appears on the top right of the Design Center. Then test your API Spec if it's working as expected.

Step 5: After testing the mock service, publish the spec to exchange (Click on Publish-> Publish to Exchange)

Step 6: Go to API Manager -> Manager API from Exchange, select the application you published in Exchange and click on Save. An API ID is generated for your application.

Develop

After writing RAML. We need to start developing the code based on it.

Step 1: For that. Goto Anypoint Studio. Create New Mule Project. Now Right-click on the project and Click Anypoint Platform --> Import from Design Center -->enter your anypoint platform credentials.

Step 2: You can see there are folders created under src/main/resources with folder names starting with API. You can see your raml under api folder

Step 3: Right-click on the project and click on Mule --> Generate Flows from REST API

This will create structured flows and half of the coding part in your flow. With API KitRouter (Which routes to that particular flow for the methods you defined in RAML or it goes to error handling if required values are not provided)

Deploy

Step 1: After completion of development. Don’t forget to Include “Auto-Discovery" Configuration where you should give API id value (explained above how to get this id ). And refer the flow to the main flow where APIkit Router is present.

Step 2: Now right-click on Project and run. Once you see your application is successfully deployed. Now copy the jar file generated under the target folder of your project.

Step 3: Now go to Anypoint Platform's Access Management. Click on the "Environments" tab, choose your env that you want your application to be deployed, get the client_id and client_secret values.

Step 4: Now to deploy Goto Anypoint Platform-->Runtime Manager -->Click on Deploy Application -->Choose File --> upload the jar file. Go to Runtime properties, add below properties:

anypoint.platform.client_id=*********************************
anypoint.platform.client_secret=*********************************

Click on Deploy.

That’s it your application is deployed. You should be seeing Active status in the API manager of your application!

Now you URL is framed as below:

http:// <application url which you can see in runtime manager>/api/<your resource name>

Manage

If you want to apply any policies, Goto AnypointPlatform --> API Manager--> Select your application --> Add new policy and apply. Simple and easy 

In this way, we can easily build our web service with less coding and more efficient performance. That's what Mule is all about!

application Design API REST MuleSoft Web Protocols

Opinions expressed by DZone contributors are their own.

Related

  • Surprisingly Simple Tools to Help You Smash API-First Approach
  • Breaking Up a Monolithic Database with Kong
  • Building REST API Backend Easily With Ballerina Language
  • Aggregating REST APIs Calls Using Apache Camel

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!