0% found this document useful (0 votes)
34 views20 pages

Mid 1

The document provides an in-depth overview of API-led connectivity, detailing its layered architecture consisting of System, Process, and Experience APIs, along with their advantages. It also distinguishes between APIs and Web Services, explains the features of the Anypoint Platform, and outlines steps for creating Mule projects for various applications such as displaying student details and managing employee data in a MySQL database. Additionally, it covers the structure of Mule applications and the concept of Mule Events.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views20 pages

Mid 1

The document provides an in-depth overview of API-led connectivity, detailing its layered architecture consisting of System, Process, and Experience APIs, along with their advantages. It also distinguishes between APIs and Web Services, explains the features of the Anypoint Platform, and outlines steps for creating Mule projects for various applications such as displaying student details and managing employee data in a MySQL database. Additionally, it covers the structure of Mule applications and the concept of Mule Events.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Unit-I

[Link] API Led connectivity in detail with example.

API Led Connectivity: API-led connectivity is an integration approach where different systems,
applications, and data sources are connected using a structured set of APIs that are reusable,
modular, and purpose-specific. Instead of building point-to-point integrations, it uses a layered
architecture to ensure flexibility, scalability, and maintainability.

Layers of API-led Connectivity:

1. System APIs

o Connect directly to core systems (databases, ERP, CRM).

o Provide raw data in a standardized format.

o Example: API to retrieve student details from a MySQL database.

2. Process APIs

o Combine and process data from multiple System APIs.

o Contain business logic but are system-independent.

o Example: API that merges student details with course enrollment data.

3. Experience APIs

o Present processed data in a format suitable for specific channels or users (web,
mobile, partner portals).

o Example: API that formats student profile for a mobile app.

Advantages:

• Reusability of APIs across multiple projects.

• Simplifies integration between heterogeneous systems.

• Improves agility and reduces development time.

• Easier to manage and secure.

Example Scenario:
In a university management system:

• System API: Fetch student personal and academic records from the database.
• Process API: Combine personal data with CGPA and attendance details.

• Experience API: Format data into JSON for mobile and web portals.

[Link] the differences between Web Services and APIs.

• API (Application Programming Interface):


A set of rules, protocols, and tools that allows one software application to communicate
with another. APIs can be used within the same application or across different systems.

• Web Service:
A type of API that is accessible over the internet or network using standard web
protocols like HTTP, SOAP, or REST.

Aspect API Web Service

Broad concept — includes any Narrower concept — only


Scope interface for communication APIs that are accessed over a
between software components. network.

Can use HTTP, HTTPS, TCP, Primarily uses HTTP and


Protocol
WebSocket, or even local system standardized protocols like
Support
calls. SOAP, REST, or XML-RPC.

Supports multiple formats: JSON, Usually XML (SOAP) or JSON


Data Format
XML, YAML, text, binary, etc. (REST).

Can be local or remote, used for Always remote, designed for


Usage
libraries, OS, or web. network-based interaction.

Java File API, Google Maps API, Currency Conversion SOAP


Examples
Twitter API. Service, Weather REST API.

Dependency on Not always dependent on a Always dependent on a


Network network. network to function.

3. Relationship

• All Web Services are APIs, but not all APIs are Web Services.
Example: A Java API for file handling is an API but not a web service.

4. Example
• API Example: Android Camera API to access camera hardware.

• Web Service Example: A weather forecast service accessible via


[Link]

[Link] is Anypoint Platform? What are the features available in Anypoint Platform.

Anypoint Platform is a unified integration platform developed by MuleSoft that allows


organizations to design, build, deploy, manage, and monitor APIs and integrations across
cloud and on-premises environments.
It enables businesses to connect applications, data, and devices through API-led
connectivity, ensuring seamless data flow and faster digital transformation.

It combines API management and integration into a single solution, making it easier to
integrate different systems, expose data as APIs, and manage their full lifecycle.

Features of Anypoint Platform

1. API Designer

o Web-based tool for designing APIs using RAML or OAS (OpenAPI Specification).

o Supports mock services for testing before actual implementation.

2. API Manager

o Enables API security, access control, and policy enforcement.

o Supports analytics and monitoring of API usage.

3. Anypoint Studio

o Eclipse-based IDE for building Mule applications and integrations visually or


through code.

o Supports connectors for various systems (databases, SaaS apps, etc.).

4. Anypoint Exchange

o A central repository to store and share APIs, connectors, templates, and


examples.

o Promotes reuse of integration assets.

5. Anypoint Runtime Manager

o Tool for deploying, managing, and monitoring applications in CloudHub or on-


premises servers.
o Offers performance monitoring and alerting.

6. DataWeave

o MuleSoft’s powerful data transformation language.

o Allows easy transformation of data formats (JSON, XML, CSV, etc.).

7. CloudHub

o MuleSoft’s managed cloud-based integration service.

o Provides scalability and reliability without managing physical servers.

8. Monitoring and Analytics

o Real-time dashboards for API and application performance.

o Helps detect issues and optimize performance.

9. Security Features

o API gateways, encryption, and authentication (OAuth 2.0, SAML, Basic Auth).

o Protects APIs from unauthorized access.

10. Hybrid Deployment

o Supports deployment in cloud, on-premises, or hybrid environments.

[Link] Mule Project to display the student details with the following fields:

o SNo, Name, Age, CGPA, Address (HNo, Street, District, State)

Steps to Create the Mule Project

1. Open Anypoint Studio

• Launch Anypoint Studio (based on Eclipse).

• Go to File → New → Mule Project.

• Name it: StudentDetailsProject.

• Runtime: Choose your Mule runtime (e.g., Mule Server 4.x).

2. Configure HTTP Listener

• Drag HTTP Listener from Mule Palette to the flow.

• Click on it → Set Path to /student.


• Configure HTTP Listener:

o Host: [Link]

o Port: 8081

o Save configuration.

3. Create the Student Data

We can use a Set Payload component to return the details.

Example JSON data:

"SNo": 1,

"Name": "John Doe",

"Age": 21,

"CGPA": 8.5,

"Address": {

"HNo": "12-34",

"Street": "MG Road",

"District": "Hyderabad",

"State": "Telangana"

4. Add Set Payload

• Drag Set Payload after HTTP Listener.

• Change Value type to JSON and paste the above JSON inside.

5. Flow XML Code

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="[Link]

xmlns="[Link]
xmlns:doc="[Link]

xmlns:xsi="[Link]

xsi:schemaLocation="

[Link]

[Link]

[Link]

[Link]

<flow name="studentDetailsFlow">

<http:listener doc:name="HTTP Listener" config-ref="HTTP_Listener_config"


path="/student"/>

<set-payload value='{

"SNo": 1,

"Name": "John Doe",

"Age": 21,

"CGPA": 8.5,

"Address": {

"HNo": "12-34",

"Street": "MG Road",

"District": "Hyderabad",

"State": "Telangana"

}' mimeType="application/json" doc:name="Set Payload"/>

</flow>

<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" >

<http:listener-connection host="[Link]" port="8081"/>

</http:listener-config>
</mule>

6. Run and Test

• Right-click → Run Project.

• Open browser or Postman:

[Link]

Unit-II

[Link] an Employee API using RAML and test them with Mock APIs.

Employee API Design using RAML and Mock Testing

RAML (RESTful API Modeling Language) is a YAML-based language used in MuleSoft to design
REST APIs before actual implementation.
It allows defining resources, methods, request/response bodies, and examples clearly.
Using Anypoint API Designer, we can design APIs and test them with Mocking Service without
writing backend code.

RAML File ([Link])

#%RAML 1.0

title: Employee API

version: v1

baseUri: [Link]

/employees:

get:

description: Retrieve all employees

responses:

200:

body:

application/json:

example:

[
{ "id": 1, "name": "John", "role": "Developer" },

{ "id": 2, "name": "Alice", "role": "Manager" }

post:

description: Add a new employee

body:

application/json:

example:

{ "id": 3, "name": "Bob", "role": "Tester" }

responses:

201:

body:

application/json:

example:

{ "message": "Employee added successfully" }

Steps to Design and Test with Mock APIs

1. Open API Designer in Anypoint Platform.

2. Create new API Specification → Select RAML 1.0.

3. Write the above RAML code for resources (/employees) and methods (GET, POST).

4. Click Save.

5. Enable Mocking Service from the toolbar.

6. Copy the Mock API URL provided by Anypoint Platform.

7. Test using Postman or a browser:

o GET request returns the sample employees list.

o POST request returns confirmation message.

Advantages of Mock Testing


• Allows frontend and backend teams to work in parallel.

• Validates API design before actual coding.

• Detects design issues early.

[Link] down the steps to configure the Mule application by importing the API from Anypoint
Platform.

Steps:

1. Open Anypoint Studio

o Launch Anypoint Studio on your system.

2. Create a New Mule Project

o Go to File → New → Mule Project.

o Enter the Project Name and select the Mule runtime version.

3. Import API from Anypoint Exchange

o In the project creation wizard, click Add from Exchange.

o Log in to your Anypoint Platform account if prompted.

o Search for the required API by name or ID.

4. Select API Asset

o From the search results, select the API specification or implementation.

o Click Add to import it into your Mule project.

5. Configure HTTP Listener

o In the Mule Palette, drag an HTTP Listener to the canvas.

o Set host (e.g., [Link]) and port (e.g., 8081) in Listener Configuration.

6. Add API Autodiscovery (Optional)

o In [Link], set the API Autodiscovery ID (from API Manager) to


connect the deployed app with API Manager for monitoring and policies.

7. Deploy the Application

o Click Run → Run As → Mule Application.

o Test the imported API endpoints using Postman or a browser.


[Link] the concept of Mule Events and illustrate their structure with a diagram.
A Mule Event is the core data unit that passes through a Mule application during execution.
Every Mule flow processes Mule events, and each event contains both the actual data being
processed and additional metadata about the transaction.

Components of a Mule Event:

1. Message – The main part of the event that carries the data.

o Payload – The actual business data (JSON, XML, text, binary, etc.).

o Attributes – Metadata describing the payload, such as HTTP headers, query


parameters, or file properties.

2. Variables – User-defined or system-generated values used temporarily within a flow for


data processing.

Example:
If a Mule application receives an HTTP request:

• Payload: JSON body containing customer details.

• Attributes: HTTP method, headers, query parameters.

• Variables: Calculated discount value stored during flow execution.

Diagram:
[Link] a Mule project to insert and retrieve the data from the MySQL database.

Mule Project to Insert and Retrieve Data from MySQL

Objective:
To design a Mule application that connects to a MySQL database and allows inserting and
retrieving employee data using HTTP endpoints.

Steps to Create the Mule Project

1. Create New Project

o Open Anypoint Studio → File → New → Mule Project.

o Name the project: EmployeeDBProject.

2. Add MySQL Database Connector

o From Mule Palette, drag Database connector.

o Configure MySQL connection:

▪ Host: localhost

▪ Port: 3306

▪ User: root

▪ Password: root

▪ Database: company.

3. Configure HTTP Listener

o Create HTTP Listener config with:

▪ Host: [Link]

▪ Port: 8081.

4. Design Flows

o Insert Flow: Uses db:insert to add data.

o Retrieve Flow: Uses db:select to fetch all rows.

Example XML Configuration

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="[Link]
xmlns="[Link]

xmlns:db="[Link]

xmlns:xsi="[Link]

xsi:schemaLocation="

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

<!-- HTTP Listener Configuration -->

<http:listener-config name="HTTP_Listener_config">

<http:listener-connection host="[Link]" port="8081"/>

</http:listener-config>

<!-- MySQL Database Configuration -->

<db:config name="MySQL_Config">

<db:my-sql-connection host="localhost" port="3306" user="root" password="root"


database="company"/>

</db:config>

<!-- Insert Employee Flow -->

<flow name="insertEmployeeFlow">

<http:listener path="/insert" config-ref="HTTP_Listener_config"/>

<db:insert config-ref="MySQL_Config">

<db:sql>

<![CDATA[

INSERT INTO employees(id, name, role)


VALUES (#[[Link]], #[[Link]], #[[Link]])

]]>

</db:sql>

</db:insert>

</flow>

<!-- Retrieve Employees Flow -->

<flow name="getEmployeesFlow">

<http:listener path="/employees" config-ref="HTTP_Listener_config"/>

<db:select config-ref="MySQL_Config">

<db:sql>SELECT * FROM employees</db:sql>

</db:select>

</flow>

</mule>

Testing the Project

• Insert Employee

o Method: POST

o URL: [Link]

o Body:

{ "id": 1, "name": "John", "role": "Developer" }

• Retrieve Employees

o Method: GET

o URL: [Link]

Diagram – Mule Flow

[HTTP Listener] → [DB Insert] → MySQL (Insert)

[HTTP Listener] → [DB Select] → MySQL (Retrieve)


Unit-III

[Link] in detail about Mule applications directories and files structure.

Mule Applications – Directories and Files Structure: A Mule application in Anypoint Studio
follows a specific project structure that organizes configuration files, resources, dependencies,
and compiled code.
This structure helps Mule runtime locate flows, connectors, and assets during execution.

1. Directory Structure Overview

When you create a Mule project in Anypoint Studio, it typically contains:

2.
Explanation of Key Directories and Files

1. src/main/mule/

o Stores Mule configuration files (*.xml) containing flows, connectors, and event
processors.

o Example:

2. src/main/resources/

o Contains non-code assets like property files (*.properties), JSON/XML schema


definitions, and data mappings.

o Used for configuration values and static data.

3. src/main/java/
o Contains custom Java classes used in the Mule application.

o Example: custom data processors or Java components.

4. src/test/java/

o Stores Java unit tests for Mule flows.

5. src/test/resources/

o Holds test property files or mock data.

6. target/

o Generated automatically after build.

o Contains compiled .class files and packaged .jar or .zip deployment files.

7. [Link]

o Describes the Mule project (name, runtime, min Mule version, secure
properties).

Example:

[Link]

o Present if the project is Maven-enabled.

o Manages dependencies, plugins, and build lifecycle.

3. Example Diagram – Mule Application Structure


[Link] and explain the various flow types available in MuleSoft.

In MuleSoft, a flow is a sequence of message processors that execute in order to process a Mule
Event. MuleSoft provides different types of flows to suit various integration needs.

1. Main Flow

• Definition: A primary executable flow that can be triggered externally (e.g., by an HTTP
request, file listener, or scheduler).

• Purpose: Handles the main business logic of an application.

• Example: An HTTP Listener triggers a flow to process a customer order.

2. Subflow

• Definition: A reusable sequence of message processors that can be invoked from other
flows using the Flow Reference component.

• Execution: Runs in the same thread as the caller flow.

• Purpose: Promotes reusability and modularity.

• Example: A subflow for logging request details, called from multiple flows.

3. Private Flow

• Definition: A flow that cannot be triggered externally; only other flows can call it.

• Execution: Runs in a separate processing thread from the calling flow.

• Purpose: Encapsulates functionality that needs asynchronous execution.


• Example: A private flow to send an email notification after processing a transaction.

4. Synchronous Flow

• Definition: Processes messages in the same thread as the caller, returning results
immediately.

• Purpose: Used when immediate response is needed and order of execution is critical.

• Example: Validating input data before storing it in a database.

5. Asynchronous Flow

• Definition: Processes messages in a different thread from the caller.

• Purpose: Improves performance for non-blocking, background tasks.

• Example: Processing a large file upload while immediately responding to the user with a
confirmation message.

[Link] to prepare a request, call a REST API and work on its response.

1. Prepare the Request

Before calling a REST API, you need to define:

• HTTP Method – GET, POST, PUT, DELETE depending on the operation.

• Endpoint URL – The web address of the API (e.g., [Link]

• Headers – Metadata such as Content-Type: application/json or authorization tokens.

• Request Body (if needed) – Data sent in POST or PUT requests, usually in JSON or XML
format.

Example Request Body (JSON):

"id": 101,

"name": "John Doe",

"email": "john@[Link]"

2. Call the REST API in MuleSoft

• Step 1: In Anypoint Studio, drag an HTTP Request component into your flow.
• Step 2: Configure the HTTP Request with:

o Method: GET/POST/PUT/DELETE.

o URL: API endpoint.

o Headers/Body: If required by the API.

• Step 3: Provide authentication details (Basic Auth, OAuth, API Key) if needed.

3. Work on the Response

When the REST API responds, MuleSoft receives:

• Payload: The actual data returned (JSON, XML, text, binary, etc.).

• Attributes: Metadata about the response (status code, headers).

Steps to process the response:

• Use Transform Message (DataWeave) to convert the payload into the required format.

• Store relevant data into variables for further processing.

• Handle error scenarios (e.g., HTTP 404 or 500) using Error Handling components.

Example Flow:

1. HTTP Listener receives a request from a client.

2. HTTP Request calls GET [Link]

3. DataWeave script formats the JSON response.

4. Response is sent back to the client.

[Link] the concept of event validation in MuleSoft and explain the role of the following
validations:
a) Is not null
b) Is Number
c) Is Email

Event Validation in MuleSoft: Event Validation in MuleSoft is the process of checking incoming
event data (payload, attributes, variables) against predefined rules to ensure the data is correct,
complete, and in the expected format before it is processed further in the flow.

MuleSoft provides Validation Module with various processors to validate data without
writing complex code.
Purpose of Event Validation

• Prevents incorrect or incomplete data from entering the system.

• Ensures application logic executes only with valid inputs.

• Improves reliability, accuracy, and security of APIs.

Common Validation Types

a) Is not null

• Definition:
Checks whether a field, variable, or payload is not empty or null.

• Use case:
Ensures mandatory fields (e.g., username, id) are provided before proceeding.

• Example:

<validation:is-not-null value="#[[Link]]" message="Name cannot be null"/>

b) Is Number

• Definition:
Verifies that the provided value is a valid number (integer or decimal).

• Use case:
Ensures numeric fields like age, price, salary contain valid numeric data.

• Example:

<validation:is-number value="#[[Link]]" message="Age must be a number"/>

c) Is Email

• Definition:
Validates whether a given string matches a valid email address pattern.

• Use case:
Ensures email inputs like user@[Link] are correctly formatted.

• Example:

<validation:is-email value="#[[Link]]" message="Invalid email format"/>

Flow Example

<flow name="validateUserFlow">
<http:listener path="/validate" config-ref="HTTP_Listener_config"/>

<validation:is-not-null value="#[[Link]]" message="Name is required"/>

<validation:is-number value="#[[Link]]" message="Age must be numeric"/>

<validation:is-email value="#[[Link]]" message="Invalid email format"/>

<set-payload value="Validation Passed"/>

</flow>

Diagram – Event Validation Process

Incoming Event

Validation Processors:

- Is Not Null

- Is Number

- Is Email

If Valid → Process Flow

If Invalid → Return Error Response

You might also like