<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Divyanicassionprinston on Medium]]></title>
        <description><![CDATA[Stories by Divyanicassionprinston on Medium]]></description>
        <link>https://medium.com/@divyanicassionprinston?source=rss-f7e9a06dba11------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lcBP91k0UM5jQYar</url>
            <title>Stories by Divyanicassionprinston on Medium</title>
            <link>https://medium.com/@divyanicassionprinston?source=rss-f7e9a06dba11------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:52:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divyanicassionprinston/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting Up OIDC Scopes, Custom Attributes and User Stores in WSO2 Identity Server]]></title>
            <link>https://medium.com/@divyanicassionprinston/setting-up-oidc-scopes-custom-attributes-and-user-stores-in-wso2-identity-server-b791e71364bf?source=rss-f7e9a06dba11------2</link>
            <guid isPermaLink="false">https://medium.com/p/b791e71364bf</guid>
            <dc:creator><![CDATA[Divyanicassionprinston]]></dc:creator>
            <pubDate>Sat, 06 Sep 2025 19:10:42 GMT</pubDate>
            <atom:updated>2025-09-06T19:10:42.124Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04CFF5H9HWkhSBoCf350YQ.png" /></figure><p>When working with modern applications, identity and access management (IAM) becomes a critical requirement. One of the most flexible open-source IAM solutions is <a href="https://wso2.com/identity-server/">WSO2 Identity Server (IS)</a>, which provides powerful support for <strong>OIDC, SAML, SCIM</strong>, and other authentication/authorization protocols.</p><p>In this guide, I’ll walk you through configuring WSO2 Identity Server for a sample project (an insurance domain portal). Along the way, we’ll:</p><ul><li>Deploy WSO2 IS locally</li><li>Create a new OIDC application</li><li>Add a <strong>custom user attribute</strong> (db_id)</li><li>Expose that attribute as part of a custom <strong>OIDC scope</strong></li><li>Configure <strong>user stores, groups, and users</strong> tied to a backend MySQL database</li></ul><p>This tutorial is intended for developers or teams looking to extend WSO2 Identity Server with custom claims and scopes while integrating with external databases.</p><h3>Deploying WSO2 Identity Server</h3><ol><li>Download the latest WSO2 Identity Server from the <a href="https://wso2.com/identity-server/">official website</a> and unzip it.</li><li>Open deployment.toml and set an <strong>offset</strong> (helpful if another WSO2 product is running on default ports)</li><li>Start the server from the bin directory:</li></ol><ul><li><strong>Windows:</strong> wso2server.bat</li><li><strong>Linux/Mac:</strong> wso2server.sh</li></ul><p>4. Once the server is up, open:</p><p>👉 <a href="https://localhost:9445/console"><strong>https://localhost:9445/console</strong></a><br>(Note: port 9445 due to offset 2).</p><p>5. Log in with default credentials:</p><ul><li>Username: admin</li><li>Password: admin</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZqygCqHUL8y-3EElmFRvQ.png" /></figure><h3>Creating an OIDC Application</h3><p>We’ll create a <strong>Single Page Application (SPA)</strong> that integrates with WSO2 IS for login.</p><ol><li>Go to <strong>Applications → New Application</strong>.</li><li>Select <strong>Single-page Application</strong>.</li><li>Configure:</li></ol><ul><li><strong>Name:</strong> Insurance</li><li><strong>Authorized Redirect URL: </strong><a href="http://localhost:5173/">http://localhost:5173/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WS0VujpLEcNXMF9wM4XBVw.png" /></figure><p>Once created, WSO2 IS provides <strong>Client ID and secrets</strong> you can use in your app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*esw1TjXuRSP_4PHXDX5eyw.png" /></figure><h3>Defining a Custom User Attribute</h3><p>In many real-world applications, you need attributes that are not part of the default WSO2 schema. For example, in our insurance portal, every user has a unique db_id that maps directly to records in MySQL.</p><ol><li>Go to <strong>User Attributes &amp; Stores → Attributes</strong>.</li><li>Click <strong>New Attribute</strong> and enter:</li></ol><ul><li>Attribute Name: db_id</li><li>Display Name: db_id</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTLplt1DGtg2xryeG19DCQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zJWCH9-rCS-1SEXSCvZbhw.png" /></figure><h3>Exposing the Attribute via OIDC Scopes</h3><p>OIDC scopes determine what claims are included in ID tokens. We’ll create a custom scope to expose our db_id.</p><ol><li>Navigate to <strong>User Attributes &amp; Stores → Attributes → OpenID Connect → Scopes</strong>.</li><li>Add a <strong>New OIDC Scope</strong>:</li></ol><ul><li>Scope: db_id</li><li>Display Name: db_id</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1yWXSrvqi1965--OUR4I0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2dpvf_1XqHBe5ku43XZBlw.png" /></figure><p>3. Associate the newly created db_id attribute.</p><p>Now, any application requesting the db_id scope will receive this attribute in tokens.</p><h3>Assigning Attributes and Scopes to the Application</h3><ol><li>Go to <strong>Applications → Insurance</strong>.</li><li>Under <strong>User Attributes</strong>, select:</li></ol><ul><li>db_id ( You can select according to your preferences )</li></ul><p>3. Save changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvVRZfm4uI8varfXzDFcgw.png" /></figure><p>This ensures that ID tokens and access tokens will contain the mapped attributes.</p><h3>Connecting a User Store</h3><p>Instead of keeping users in the default WSO2 store, let’s integrate with a <strong>MySQL user database</strong>.</p><ol><li>Navigate to <strong>User Attributes &amp; Stores → User Stores → New User Store</strong>.</li></ol><p>2. Select <strong>Database</strong> as the type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ox4iWdlOcIKSItGM8gKX6A.png" /></figure><p>3. Configure:</p><ul><li>Name: insurance</li><li>Connection URL:</li></ul><pre>jdbc:mysql://localhost:3306/insurance</pre><ul><li>Username: root</li><li>Password: root_password</li><li>Driver: com.mysql.cj.jdbc.Driver</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oewmm-FPATeI0EuxAHjfbw.png" /></figure><p>Now, users from the insurance database can be managed through created user store.</p><h3>Creating Groups</h3><p>Groups help define <strong>roles</strong> within the system. In our insurance portal, we’ll create three groups:</p><ol><li>Navigate to <strong>User Management → Groups</strong>.</li><li>Select the insurance user store.</li><li>Add:</li></ol><ul><li>Customer</li><li>Employee</li><li>admin</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QvlD7KCpielw5Rurc038Ag.png" /></figure><h3>Adding Users</h3><p>Since this is an insurance system, self-registration is <strong>disabled</strong>. Users are created manually:</p><ol><li>Go to <strong>User Management → Users → Add User</strong>.</li><li>Choose the insurance store.</li><li>Provide:</li></ol><ul><li>Username: (from database)</li><li>db_id: (as per MySQL records)</li><li>Password: (set manually or your can use any other options )</li></ul><p>4. Assign the user to one of the groups (Customer, Employee, admin).</p><h3>Key Takeaways</h3><p>By following this setup, you:</p><ul><li>Configured WSO2 Identity Server with a <strong>custom user attribute (</strong><strong>db_id)</strong></li><li>Exposed it via a <strong>custom OIDC scope</strong></li><li>Integrated with an <strong>external MySQL user store</strong></li><li>Created <strong>groups and users</strong> tied to real database records</li></ul><p>This setup is especially useful when:</p><ul><li>Your app needs <strong>claims directly tied to business logic</strong> (like customer/employee IDs)</li><li>You want to <strong>extend OIDC scopes</strong> beyond default claims</li><li>You’re managing identities across multiple databases and domains</li></ul><p>I hope you found something useful here. It’s been a real pleasure writing this for you, let’s keep learning together!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b791e71364bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple Walkthrough into JWT Tokens and Opaque Tokens]]></title>
            <link>https://medium.com/@divyanicassionprinston/a-simple-walkthrough-into-jwt-tokens-and-opaque-tokens-bc3572bdeb49?source=rss-f7e9a06dba11------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc3572bdeb49</guid>
            <dc:creator><![CDATA[Divyanicassionprinston]]></dc:creator>
            <pubDate>Fri, 29 Aug 2025 07:29:41 GMT</pubDate>
            <atom:updated>2025-08-29T07:29:41.977Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8F5uIXcX1X9Py4n6uNPung.png" /></figure><p>In today’s web world, security and identity are key pillars. Whether you’re logging into a website, using a mobile app, or making an API call, <strong>tokens</strong> are often used to represent “who you are” and what you’re allowed to do.</p><p>But not all tokens are created equal. In this post, let’s take a simple walkthrough into two common types: <strong>JWT (JSON Web Tokens)</strong> and <strong>opaque tokens</strong>.</p><h3>What Is a Token, Anyway?</h3><p>Imagine you log in to a website. Instead of asking for your password every time you click a button or visit a page, the server gives you a <strong>token</strong> — kind of like a “Hey, I know this person” card.</p><p>This token is what you’ll send along with your future requests. The server checks the token, nods, and lets you through.</p><p>But here’s the twist: Not all tokens look the same. Some are like transparent name tags (<strong>JWT</strong>), others are just secret codes (<strong>opaque tokens</strong>). Let’s unpack that.</p><p>A <strong>token</strong> is like a temporary ID card that a system gives you after you log in. Instead of sending your password with every request, you send this token.</p><p>This token helps the server know:</p><ul><li>Who you are</li><li>Whether you’re allowed to access something</li><li>When your token will expire</li></ul><p>There are two main types of tokens you’ll commonly run into: <strong>JWT tokens</strong> and <strong>opaque tokens</strong>.</p><h3>JWT Tokens — Tokens You Can Read</h3><p><strong>JWT (JSON Web Token)</strong> is a token that contains actual user data <strong>inside</strong> the token itself. It’s formatted in three parts:</p><pre>&lt;Header&gt;.&lt;Payload&gt;.&lt;Signature&gt;</pre><p>Example:</p><pre>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. <br>eyJ1c2VySWQiOiIxMjM0IiwibmFtZSI6IkFsaWNlIn0. <br>dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk</pre><p>You can paste a JWT into <a href="https://jwt.io/">jwt.io</a> and instantly decode it (well, except the signature).</p><h3>Pros of JWT:</h3><ul><li><strong>Self-contained</strong>: All user info (like userId, email, roles) is inside the token.</li><li><strong>Stateless</strong>: No need to store session data on the server.</li><li><strong>Quick checks</strong>: You can verify permissions without calling a database.</li></ul><h3>Cons of JWT:</h3><ul><li><strong>Security risk if leaked</strong>: Anyone can read the token content (unless encrypted).</li><li><strong>Hard to revoke</strong>: Once issued, it’s hard to “invalidate” unless you store a blacklist.</li><li><strong>Larger size</strong>: The token contains more data than just an ID.</li></ul><h3>Opaque Tokens — Tokens You Can’t Read</h3><p><strong>Opaque tokens</strong> look like random strings:</p><pre>v9B6V6M9FnxqQTLWyqWQ3Mg0pQw9gOBL</pre><p>They don’t hold any readable information. Instead, they act as a <strong>reference key</strong>. The server must look it up in a <strong>token database or introspection endpoint</strong> to get user details.</p><p>Think of it like a cloakroom token at a hotel, the number means nothing to you, but the concierge knows exactly which coat it refers to.</p><h3>Pros of Opaque :</h3><ul><li><strong>More secure</strong>: Since nothing is exposed in the token, you can’t tell what it contains if intercepted.</li><li><strong>Easy to revoke</strong>: The server keeps full control and can invalidate the token anytime.</li><li><strong>Smaller size</strong>: Just a random string.</li></ul><h3>Cons of Opaque :</h3><ul><li><strong>Needs lookup</strong>: The server has to check the token’s validity every time.</li><li><strong>Slightly slower</strong>: It may add a small delay due to introspection.</li></ul><h3>Which One Should You Use?</h3><p><strong>Use JWT</strong> when:</p><ul><li>You need stateless APIs</li><li>You want fast, no-database-required authorization</li><li>You’re okay with short-lived tokens that don’t need revoking</li></ul><p><strong>Use opaque tokens</strong> when:</p><ul><li>You want more control and revocation capabilities</li><li>You handle sensitive information</li><li>You’re okay with slightly more latency</li></ul><h3>Bonus Tip: Hybrid Approaches</h3><p>In real systems like <strong>OAuth 2.0</strong> or <strong>OpenID Connect</strong>, you actually get to use both types of tokens — each for a different job:</p><ul><li><strong>Access tokens</strong> (used to call APIs) are usually <strong>opaque —</strong> private and secure.</li><li><strong>ID tokens</strong> (used to know who the user is) are <strong>JWTs</strong> — easy to read and quick to process.</li></ul><p>This way, you get the best of both worlds: secure, revocable access tokens and readable identity info when needed.</p><h3>Final Thoughts</h3><p>Both JWT and opaque tokens are widely used for user authentication and authorization in modern applications. There’s no one-size-fits-all — your choice depends on the <strong>security requirements</strong>, <strong>performance needs</strong>, and <strong>infrastructure setup</strong> of your project.</p><p>The key takeaway:<br> <strong>JWT is like a passport with your info written inside. Opaque tokens are like a hotel key card , useless without the system behind it.</strong></p><p>Now you have a basic idea of this simple concept, and I hope it helps you at some point.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc3572bdeb49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplifying JSON Handling within WSO2 Micro Integrator with REST Data Services]]></title>
            <link>https://medium.com/@divyanicassionprinston/simplifying-json-handling-within-wso2-micro-integrator-with-rest-data-services-8096a357b263?source=rss-f7e9a06dba11------2</link>
            <guid isPermaLink="false">https://medium.com/p/8096a357b263</guid>
            <dc:creator><![CDATA[Divyanicassionprinston]]></dc:creator>
            <pubDate>Fri, 29 Aug 2025 07:28:09 GMT</pubDate>
            <atom:updated>2025-09-11T18:22:28.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jvwX6Gva-ALZSATtI5_1sg.png" /></figure><p>In many of our integration projects, we rely on Micro Integrator (MI) to expose databases as services. By default, MI Data Services return XML responses, which often require extra work to transform or parse on the frontend , especially in modern JavaScript based applications that expect JSON.</p><p>To address this, I’ve explored a simple yet effective approach: wrapping the original MI Data Service inside a REST API with jsontransform, making JSON consumption smooth and frontend-friendly.</p><h3>The Challenge</h3><p>When you create a Data Service in WSO2 MI, the default response is in XML. While you <em>can</em> get JSON by passing specific headers, this often leads to inconsistencies and extra effort in mapping on the frontend.</p><p>So, I asked myself:</p><blockquote>Why not wrap the Data Service inside a REST API, handle the transformation within MI, and return clean JSON to the client?</blockquote><blockquote><strong>Note:</strong> <br>This approach is recommended when it is <strong>compulsory</strong> to handle the transformation of the Data Service within MI. Otherwise, you can simply use APIM policies to perform the transformation with a straightforward header configuration.</blockquote><h3>The Solution</h3><ul><li>Create the MI Data Service</li><li>Wrap the Data Service with an API</li><li>Use jsontransform in the Sequence</li><li>Avoid frontend-side parsing and mapping</li></ul><p>Let’s go step-by-step in to demonstation…</p><h4><strong>Step 1: Create the Data Service</strong></h4><ol><li>Choose a project name and create a MI project workspace in Visual Studio Code, as illustrated below.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*Q4v-iqmUYAopYS1U.png" /></figure><p>2. Select Data service under artifacts and choose a name for the for the data Service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*313J8fHqHtOcPin1.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*3e48Qlr503SFIV-D.png" /></figure><p>3. As we are trying to connect with MySQL, you should select RDBMS for the Data source Type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*jEjzfn1A4ocnxTru.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*mmOjf8JUHWwh43KL.png" /></figure><p>4. An important step to consider is adding the appropriate JDBC driver version that is compatible with your database. Ensure the connection is configured correctly by providing the valid database name and password.</p><p>Then, test the connection to confirm that it has been successfully established, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*Y3vTNM6ZOrQihq6o.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*GJ6zS_B5LK4otisl.png" /></figure><p>5. Now that you have successfully created the Data Service, you can proceed to add the necessary resources based on the specific requirements of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*VXrqFNS-t-zcuZmV.png" /></figure><p>I’ve attached the code for RESTDataService.dbs, which you can readily use in your project.</p><pre>&lt;data name=&quot;InsuranceEmployeesService&quot; transports=&quot;http https&quot; serviceType=&quot;data&quot; media-type=&quot;json&quot;&gt;<br>    &lt;config id=&quot;default&quot;&gt;<br>        &lt;property name=&quot;driverClassName&quot;&gt;com.mysql.cj.jdbc.Driver&lt;/property&gt;<br>        &lt;property name=&quot;url&quot;&gt;jdbc:mysql://localhost:3306/insurance&lt;/property&gt;<br>        &lt;property name=&quot;username&quot;&gt;db_user&lt;/property&gt;<br>        &lt;property name=&quot;password&quot;&gt;db_password&lt;/property&gt;<br>    &lt;/config&gt;<br><br>    &lt;!-- Get All Employees --&gt;<br>    &lt;query id=&quot;getAllEmployees&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;SELECT * FROM employees&lt;/sql&gt;<br>        &lt;result outputType=&quot;json&quot;&gt;{<br>            &quot;Employees&quot;: {<br>                &quot;Employee&quot;: [<br>                    {<br>                        &quot;employee_id&quot;: &quot;$employee_id&quot;,<br>                        &quot;first_name&quot;: &quot;$first_name&quot;,<br>                        &quot;last_name&quot;: &quot;$last_name&quot;,<br>                        &quot;role&quot;: &quot;$role&quot;,<br>                        &quot;email&quot;: &quot;$email&quot;,<br>                        &quot;phone&quot;: &quot;$phone&quot;,<br>                        &quot;created_at&quot;: &quot;$created_at&quot;,<br>                        &quot;address&quot;: &quot;$address&quot;<br>                    }<br>                ]<br>            }<br>        }&lt;/result&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;GET&quot; path=&quot;/employees&quot;&gt;<br>        &lt;call-query href=&quot;getAllEmployees&quot;/&gt;<br>    &lt;/resource&gt;<br><br>    &lt;!-- Get Employee by ID --&gt;<br>    &lt;query id=&quot;getEmployeeById&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;SELECT * FROM employees WHERE employee_id = :employee_id&lt;/sql&gt;<br>        &lt;result outputType=&quot;json&quot;&gt;{<br>            &quot;Employee&quot;: {<br>                &quot;employee_id&quot;: &quot;$employee_id&quot;,<br>                &quot;first_name&quot;: &quot;$first_name&quot;,<br>                &quot;last_name&quot;: &quot;$last_name&quot;,<br>                &quot;role&quot;: &quot;$role&quot;,<br>                &quot;email&quot;: &quot;$email&quot;,<br>                &quot;phone&quot;: &quot;$phone&quot;,<br>                &quot;created_at&quot;: &quot;$created_at&quot;,<br>                &quot;address&quot;: &quot;$address&quot;<br>            }<br>        }&lt;/result&gt;<br>        &lt;param name=&quot;employee_id&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;GET&quot; path=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;call-query href=&quot;getEmployeeById&quot;&gt;<br>            &lt;with-param name=&quot;employee_id&quot; query-param=&quot;employee_id&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br><br><br>    &lt;!-- Insert Employee --&gt;<br>    &lt;query id=&quot;createEmployee&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;<br>            INSERT INTO employees (first_name, last_name, role, email, phone, created_at, address)<br>            VALUES (:first_name, :last_name, :role, :email, :phone, NOW(), :address)<br>        &lt;/sql&gt;<br>        &lt;param name=&quot;first_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;last_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;role&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;email&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;phone&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;address&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;POST&quot; path=&quot;/employee&quot;&gt;<br>        &lt;call-query href=&quot;createEmployee&quot;&gt;<br>            &lt;with-param name=&quot;first_name&quot; query-param=&quot;first_name&quot;/&gt;<br>            &lt;with-param name=&quot;last_name&quot; query-param=&quot;last_name&quot;/&gt;<br>            &lt;with-param name=&quot;role&quot; query-param=&quot;role&quot;/&gt;<br>            &lt;with-param name=&quot;email&quot; query-param=&quot;email&quot;/&gt;<br>            &lt;with-param name=&quot;phone&quot; query-param=&quot;phone&quot;/&gt;<br>            &lt;with-param name=&quot;address&quot; query-param=&quot;address&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br><br>    &lt;!-- Update Employee --&gt;<br>    &lt;query id=&quot;updateEmployee&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;<br>            UPDATE employees<br>            SET first_name = :first_name,<br>                last_name = :last_name,<br>                role = :role,<br>                email = :email,<br>                phone = :phone,<br>                address = :address<br>            WHERE employee_id = :employee_id<br>        &lt;/sql&gt;<br>        &lt;param name=&quot;employee_id&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;first_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;last_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;role&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;email&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;phone&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;address&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;PUT&quot; path=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;call-query href=&quot;updateEmployee&quot;&gt;<br>            &lt;with-param name=&quot;employee_id&quot; query-param=&quot;employee_id&quot;/&gt;<br>            &lt;with-param name=&quot;first_name&quot; query-param=&quot;first_name&quot;/&gt;<br>            &lt;with-param name=&quot;last_name&quot; query-param=&quot;last_name&quot;/&gt;<br>            &lt;with-param name=&quot;role&quot; query-param=&quot;role&quot;/&gt;<br>            &lt;with-param name=&quot;email&quot; query-param=&quot;email&quot;/&gt;<br>            &lt;with-param name=&quot;phone&quot; query-param=&quot;phone&quot;/&gt;<br>            &lt;with-param name=&quot;address&quot; query-param=&quot;address&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br><br>    &lt;!-- Delete Employee --&gt;<br>    &lt;query id=&quot;deleteEmployee&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;DELETE FROM employees WHERE employee_id = :employee_id&lt;/sql&gt;<br>        &lt;param name=&quot;employee_id&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;DELETE&quot; path=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;call-query href=&quot;deleteEmployee&quot;&gt;<br>            &lt;with-param name=&quot;employee_id&quot; query-param=&quot;employee_id&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br>&lt;/data&gt;</pre><h3>Step 2: Create the API to Wrap Data Service</h3><p>We now create an API named employees-api that internally calls the above data service. The key trick is using a &lt;jsontransform&gt; mediator in the outSequence to ensure JSON output regardless of the backend format.</p><p>Here’s an example for GET /employees:</p><pre>&lt;resource methods=&quot;GET&quot; uri-template=&quot;/employees&quot;&gt;<br>    &lt;inSequence&gt;<br>        &lt;send&gt;<br>            &lt;endpoint&gt;<br>                &lt;http method=&quot;GET&quot; uri-template=&quot;http://localhost:8290/services/InsuranceEmployeesService/employees&quot;/&gt;<br>            &lt;/endpoint&gt;<br>        &lt;/send&gt;<br>    &lt;/inSequence&gt;<br>    &lt;outSequence&gt;<br>        &lt;property name=&quot;messageType&quot; scope=&quot;axis2&quot; value=&quot;application/json&quot;/&gt;<br>        &lt;jsontransform&gt;<br>            &lt;property name=&quot;synapse.commons.json.output.autoPrimitive&quot; value=&quot;false&quot;/&gt;<br>        &lt;/jsontransform&gt;<br>        &lt;respond/&gt;<br>    &lt;/outSequence&gt;<br>&lt;/resource&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1s4FbECI5bichn2vTNXwnw.png" /></figure><p>The highlighted XML snippet defines a REST resource in a WSO2 Data Service that handles HTTP GET requests to the path /employees. When this endpoint is accessed, it triggers the getAllEmployees query, which retrieves all employee records from the database. The results are then returned to the client in JSON format. This setup allows clients to easily fetch a list of all employees by making a simple GET request to the specified endpoint, abstracting away the underlying database operations and providing a clean, RESTful API interface.</p><p>Similarly, create an API for all other resources.</p><p>An example for POST /employee:</p><pre>&lt;resource methods=&quot;POST&quot; uri-template=&quot;/employee&quot;&gt;<br>        &lt;inSequence&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;property name=&quot;ContentType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;property name=&quot;HTTP_METHOD&quot; scope=&quot;axis2&quot; value=&quot;POST&quot;/&gt;<br>            &lt;property name=&quot;uri.var.first_name&quot; expression=&quot;json-eval($.employee.first_name)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.last_name&quot; expression=&quot;json-eval($.employee.last_name)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.role&quot; expression=&quot;json-eval($.employee.role)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.email&quot; expression=&quot;json-eval($.employee.email)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.phone&quot; expression=&quot;json-eval($.employee.phone)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.address&quot; expression=&quot;json-eval($.employee.address)&quot;/&gt;<br>            &lt;send&gt;<br>                &lt;endpoint&gt;<br>                    &lt;http method=&quot;POST&quot; uri-template=&quot;http://localhost:8290/services/InsuranceEmployeesService/employee?employee_id={uri.var.employee_id}&amp;amp;first_name={uri.var.first_name}&amp;amp;last_name={uri.var.last_name}&amp;amp;role={uri.var.role}&amp;amp;email={uri.var.email}&amp;amp;phone={uri.var.phone}&amp;amp;address={uri.var.address}&quot;/&gt;<br>                &lt;/endpoint&gt;<br>            &lt;/send&gt;<br>        &lt;/inSequence&gt;<br>        &lt;outSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;success&quot;, &quot;message&quot;: &quot;Employee Successfully Created!&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;jsontransform&gt;<br>                &lt;property name=&quot;synapse.commons.json.output.autoPrimitive&quot; value=&quot;false&quot;/&gt;<br>            &lt;/jsontransform&gt;<br>            &lt;respond/&gt;<br>        &lt;/outSequence&gt;<br>        &lt;faultSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Error creating employee&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;respond/&gt;<br>        &lt;/faultSequence&gt;<br>    &lt;/resource&gt;</pre><p>You might wonder:</p><blockquote>Why call an endpoint from another endpoint? Isn’t that redundant?</blockquote><p>Actually, this pattern offers multiple benefits:</p><ul><li><strong>Separation of concerns</strong>: Keep data logic and API logic separate.</li><li><strong>JSON by default</strong>: Avoid frontend-side parsing or headers.</li><li><strong>Cleaner frontend code</strong>: No need for XML → JSON conversion or complex mapping.</li><li><strong>Flexible mapping</strong>: You can add additional logic (e.g., filtering, validation) inside the API easily.</li></ul><h3>Example Output</h3><p>Here’s how a response would look for GET /employees-api/employees:</p><pre>{&quot;Employee&quot;: <br>      {<br>        &quot;employee_id&quot;: &quot;E101&quot;,<br>        &quot;first_name&quot;: &quot;Alice&quot;,<br>        &quot;last_name&quot;: &quot;Fernandez&quot;,<br>        &quot;role&quot;: &quot;Manager&quot;,<br>        &quot;email&quot;: &quot;alice@domain.com&quot;,<br>        &quot;phone&quot;: &quot;0771234567&quot;,<br>        &quot;created_at&quot;: &quot;2025-07-10 09:30:00&quot;,<br>        &quot;address&quot;: &quot;Colombo&quot;<br>      }<br>}</pre><h3>Conclusion</h3><p>This simple design pattern — wrapping a Data Service with a REST API, solves a real problem when working with JSON clients in a service-oriented architecture. It’s flexible, scalable, and most importantly FE friendly.</p><p>🔗 <strong>You can find the complete source code here:</strong></p><p><a href="https://github.com/DivyaniCassionPrinston/Employee-Dataservice-JSON-res">GitHub - DivyaniCassionPrinston/Employee-Dataservice-JSON-res</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8096a357b263" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Scalable API with Ballerina using bal persist,  MySQL & GraphQL]]></title>
            <link>https://medium.com/@divyanicassionprinston/building-a-scalable-api-with-ballerina-using-bal-persist-mysql-graphql-b8017b71e8aa?source=rss-f7e9a06dba11------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8017b71e8aa</guid>
            <dc:creator><![CDATA[Divyanicassionprinston]]></dc:creator>
            <pubDate>Sun, 06 Jul 2025 04:12:24 GMT</pubDate>
            <atom:updated>2025-07-13T17:20:36.753Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building a Scalable API with Ballerina using bal persist, MySQL &amp; GraphQL</strong></h3><p>Hey folks! 👋<br> I recently worked on a fun and practical project — creating a <strong>GraphQL API</strong> for managing insurance products using <strong>Ballerina</strong>, connected to a <strong>MySQL</strong> database, and finally Docker for smooth deployment.<br> In this article, I’ll walk you through what I did, how it works, and why it might help you too!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHhddramGjXm72gCjrcn_w.png" /></figure><h3>What’s This Project About?</h3><p>The main goal of this project was to build a backend service with <strong>Ballerina </strong>that can <strong>create</strong>, <strong>read</strong>, <strong>update</strong>, and <strong>delete</strong> insurance products (CRUD), and expose that functionality through a flexible GraphQL API.</p><p>I used:</p><ul><li><strong>Ballerina</strong> ( bal persist)</li><li><strong>MySQL</strong> as the database</li><li><strong>Postman/GraphiQL</strong> for testing</li></ul><h3>Ballerina with GraphQL …</h3><p>One of the key strengths of Ballerina is its <strong>first-class support for GraphQL</strong> through its standard library. Unlike many other languages that require third-party GraphQL libraries, Ballerina includes everything you need out-of-the-box. This reduces external dependencies and simplifies project setup.</p><p>Ballerina’s <strong>strong type system</strong> ensures that GraphQL operations are fully type-safe. This means that all queries, inputs, and return types are explicitly defined and validated at compile-time, reducing runtime errors and improving developer confidence. The types declared in your service automatically reflect in the GraphQL schema.</p><p>The <strong>syntax is concise, declarative, and developer-friendly</strong>. You can define queries and mutations using familiar resource and remote functions, while avoiding the verbosity seen in many backend frameworks. Mapping between database results and GraphQL types becomes seamless due to the record-based structure of Ballerina.</p><p>Another major advantage is Ballerina’s ability to <strong>auto-generate the GraphQL schema</strong> from your code. As you add or modify functions in your service, the schema updates dynamically — eliminating the need to maintain schema files manually. This feature significantly reduces boilerplate and development overhead.</p><p>Ballerina includes built-in support for the <strong>GraphiQL playground</strong>, which is a web interface for testing GraphQL queries. With just one line in the service configuration, you can expose a fully interactive playground for debugging, testing, and visualizing your schema, improving development and documentation processes.</p><p>For data-heavy queries, Ballerina supports <strong>streaming capabilities</strong>, allowing you to handle large sets of data efficiently. This is particularly useful for APIs dealing with dynamic datasets or performing filtered searches, where you don’t want to load everything into memory at once.</p><p>Security and deployment flexibility are also built into the language. With <strong>configurable variables</strong>, you can externalize sensitive values like database credentials, hostnames, and ports. This makes the application more secure and allows seamless deployment across different environments such as development, staging, and production.</p><p>Finally, Ballerina provides a <strong>great developer experience</strong> with features like real-time error highlighting, a powerful command-line interface, and support for hot-reloading services. These capabilities speed up the development cycle and make Ballerina a pleasure to use for GraphQL microservices.</p><p>Likewise, there are many benefits to using Ballerina with GraphQL. Let’s dive into the project so you can see just how easy it is to build a powerful GraphQL API with Ballerina.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSnl5R2XGHTHEqOvHp6JsQ.png" /></figure><h3><strong>Use Case:</strong></h3><p>Imagine an application where users or admins manage different types of insurance plans/products (health, vehicle, life, etc). Each product has Name, Description, Coverage type &amp; amount, Deductible and Premium</p><p>The data is stored in a simple products table, and the backend exposes queries and mutations to manage these products.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*g4EMooXwc5eumm8QwhXvIQ.jpeg" /></figure><h3>Setting the Groundwork</h3><p>To get started, create a basic Ballerina project template by running the following command.</p><pre>bal new product-api</pre><p>You can create the local database by executing the following SQL script.</p><pre>CREATE DATABASE IF NOT EXISTS insurance_db;<br>USE insurance_db;<br><br>CREATE TABLE IF NOT EXISTS insurance_products (<br>    id INT PRIMARY KEY AUTO_INCREMENT,<br>    name VARCHAR(255) NOT NULL,<br>    description TEXT,<br>    coverage_type VARCHAR(100),<br>    coverage_amount DECIMAL(15, 2),<br>    deductible DECIMAL(15, 2),<br>    premium VARCHAR(50)<br>);<br><br>INSERT INTO insurance_products (name, description, coverage_type, coverage_amount, deductible, premium) VALUES<br>(&#39;Basic Health Plan&#39;, &#39;Covers general medical expenses&#39;, &#39;Health&#39;, 10000.00, 500.00, &#39;50/month&#39;),<br>(&#39;Comprehensive Car Insurance&#39;, &#39;Full coverage for vehicle damages&#39;, &#39;Auto&#39;, 25000.00, 1000.00, &#39;120/month&#39;),<br>(&#39;Homeowners Insurance&#39;, &#39;Protection for home damages and theft&#39;, &#39;Home&#39;, 50000.00, 2000.00, &#39;75/month&#39;),<br>(&#39;Travel Insurance&#39;, &#39;Covers trip cancellations and medical emergencies&#39;, &#39;Travel&#39;, 15000.00, 300.00, &#39;30/trip&#39;),<br>(&#39;Life Insurance Premium&#39;, &#39;Provides financial security for loved ones&#39;, &#39;Life&#39;, 100000.00, 5000.00, &#39;200/year&#39;);</pre><p>You can now begin using bal persist by navigating into the Ballerina project directory. Then, run the command below to create a data model inside the persist folder.</p><pre>bal persist init --module db --datastore mysql</pre><p>Next, generate the client and db_config.bal files by running the command below. This prepares the base setup for the final step.</p><pre>bal persist generate --datastore mysql</pre><p>You need to update the config file with the correct database credentials to establish a successful connection.</p><pre>import ballerinax/mysql;<br><br>configurable int port = 3306;<br>configurable string host = &quot;localhost&quot;;<br>configurable string user = &quot;root&quot;;   #Replace your db user<br>configurable string database = &quot;insurance_db&quot;;<br>configurable string password = &quot;******&quot;;   #Replace your db password</pre><p>Finally, complete the setup with the main.bal file to expose your endpoints via GraphQL. Follow the code snippet below to create a new DB client instance, which will handle all persistence operations using the persist_client. Then, you can call the relevant resources from it.</p><pre>final db:Client dbClient = check new db:Client();<br><br>@graphql:ServiceConfig {<br>    graphiql: {enabled: true}<br>}<br>service /insurance on new graphql:Listener(9091) {</pre><p>Get all insurance products</p><pre>resource function get all() returns db:Product[]|error {<br>        stream&lt;db:Product, error?&gt; productStream = dbClient-&gt;/products;<br>        db:Product[] products = [];<br><br>        check from db:Product product in productStream<br>            do {<br>                products.push(product);<br>            };<br><br>        return products;<br>    }</pre><p>Filter insurance products by coverage type</p><pre>resource function get filterByCoverageType(string coverageType) returns db:Product[]|error {<br>        stream&lt;db:Product, error?&gt; productStream = dbClient-&gt;/products.get(whereClause = `coverage_type = ${coverageType}`);<br>        db:Product[] products = [];<br><br>        check from db:Product product in productStream<br>            do {<br>                products.push(product);<br>            };<br><br>        return products;<br>    }</pre><p>Get insurance a product by it’s ID</p><pre>resource function get getProductById(int id) returns db:Product|error {<br>        db:Product product = check dbClient-&gt;/products/[id];<br>        return product;<br>    }</pre><p>Add new insurance product</p><pre>remote function add(db:ProductInsert product) returns db:Product|error {<br>        int[] ids = check dbClient-&gt;/products.post([product]);<br><br>        if ids.length() == 0 {<br>            return error(&quot;Failed to create product&quot;);<br>        }<br><br>        db:Product insertedProduct = check dbClient-&gt;/products/[ids[0]];<br>        return insertedProduct;<br>    }</pre><p>Refer to the visual diagram below for the POST operation. Similarly, you can explore the visualizer for more insights into other operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*7TZ5a5NaJ9vqomW6WE5-wA.png" /></figure><p>Update an existing insurance product</p><pre>remote function update(int id, db:ProductUpdate product) returns db:Product|error {<br>        db:Product updatedProduct = check dbClient-&gt;/products/[id].put(product);<br>        return updatedProduct;<br>    }</pre><p>Delete an insurance product by ID</p><pre>remote function delete(int id) returns db:Product|error {<br>        db:Product deletedProduct = check dbClient-&gt;/products/[id].delete();<br>        return deletedProduct;<br>    }</pre><p>Close client resources when service stops</p><pre>function beforeExit() returns error? {<br>        check dbClient.close();<br>    }</pre><p>Now you’re all set! Use the following command to start up the project :</p><pre>bal run </pre><p>The GraphQL service will start on port 9091, and you can access the GraphiQL interface at: <a href="http://localhost:9091/graphiql">http://localhost:9091/graphiql</a></p><p>You can test it using the GraphQL client we created earlier, or alternatively, use Postman as demonstrated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZA6PVu0r9QbqUbWZDRM8MA.png" /></figure><p>Below are sample <strong>GraphQL queries and mutations</strong> that you can use to test the API using a GraphQL client such as <strong>GraphiQL</strong> or <strong>Postman</strong>. These examples demonstrate how to interact with the service for retrieving, adding, updating, and deleting insurance products.</p><h3><strong>Queries</strong></h3><ol><li>Get all products:</li></ol><pre>query {<br>  all {<br>    id<br>    name<br>    description<br>    coverageType<br>    coverageAmount<br>    deductible<br>    premium<br>  }<br>}</pre><p>2. Get product by ID:</p><pre>query {<br>  getProductById(id: 1) {<br>    id<br>    name<br>    description<br>    coverageType<br>    coverageAmount<br>    deductible<br>    premium<br>  }<br>}</pre><p>3. Filter products by coverage type:</p><pre>query {<br>  filterByCoverageType(coverageType: &quot;Health&quot;) {<br>    id<br>    name<br>    description<br>    coverageAmount<br>    deductible<br>    premium<br>  }<br>}</pre><h3><strong>Mutations</strong></h3><ol><li>Add a new product:</li></ol><pre>mutation {<br>  add(<br>    product: {<br>      name: &quot;Health Insurance Plus&quot;<br>      description: &quot;Comprehensive health coverage&quot;<br>      coverageType: &quot;Health&quot;<br>      coverageAmount: 500000<br>      deductible: 1000<br>      premium: &quot;100/month&quot;<br>    }<br>  ) {<br>    id<br>    name<br>    description<br>  }<br>}</pre><p>2. Update an existing product:</p><pre>mutation {<br>  update(id: 1, product: { premium: &quot;120/month&quot;, coverageAmount: 600000 }) {<br>    id<br>    name<br>    premium<br>    coverageAmount<br>  }<br>}</pre><p>3. Delete a product:</p><pre>mutation {<br>  delete(id: 1) {<br>    id<br>    name<br>  }<br>}</pre><h3><strong>Why bal persists…?</strong></h3><p><strong>bal persist enables seamless data persistence by allowing you to <em>define the data model</em> and <em>utilize generated client API</em></strong></p><p><strong>bal persist offers,</strong></p><ul><li><strong>Simplified Database Interaction</strong> — <em>Eliminate the need to write low-level and complex SQL queries</em></li><li><strong>Developer Productivity</strong> — <em>Abstract away the details of the underlying database and provide a more intuitive interface</em></li><li><strong>Data Mapping</strong> — <em>Handle the mapping between the data-oriented world and the relational database model</em></li><li><strong>Database Independence</strong> — <em>Allow developers to switch between different database providers without major code changes</em></li><li><strong>Consistency and Integrity</strong> — <em>Manage transactions and apply database constraints</em></li></ul><h3>🧠 Why bal persist is a Game-Changer</h3><p>Here are some reasons to love bal persist:</p><ul><li>Less boilerplate — no manual SQL or result streams</li><li>Auto-generated table creation (perfect for prototyping)</li><li>Type-safe queries using Ballerina’s query expressions</li><li>Cleaner error handling</li><li>Works seamlessly with MySQL, PostgreSQL, and more!</li></ul><p>🔗 F<strong>ind the complete source code and project files here:</strong></p><p><a href="https://github.com/DivyaniCassionPrinston/Products-API-with-Ballerina">GitHub - DivyaniCassionPrinston/Products-API-with-Ballerina</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8017b71e8aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containerizing WSO2 Micro Integrator Data service project with MySQL to Deliver Scalable REST APIs]]></title>
            <link>https://medium.com/@divyanicassionprinston/containerizing-wso2-micro-integrator-data-service-project-with-mysql-to-deliver-scalable-rest-apis-fe625af44d65?source=rss-f7e9a06dba11------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe625af44d65</guid>
            <dc:creator><![CDATA[Divyanicassionprinston]]></dc:creator>
            <pubDate>Fri, 04 Jul 2025 04:21:56 GMT</pubDate>
            <atom:updated>2025-07-04T04:21:56.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSVFv-gbliEn2uLl3lhuYQ.png" /></figure><p>Hi everyone! If you’ve landed here, chances are you’re familiar, at least a little with WSO2 Micro Integrator or Docker. But if you’re not, don’t worry! This guide will help you grasp the basics as we walk through a simple integration project.</p><p>In this project, we’ll use:</p><ul><li><strong><em>WSO2 Micro Integrator (WSO2 MI)</em></strong></li><li><strong><em>Rancher Desktop (with optional WSL support on Windows)</em></strong></li><li><strong><em>MySQL</em></strong></li><li><strong><em>Docker</em></strong></li></ul><h3>What is WSO2 Micro Integrator?</h3><p>WSO2 Micro Integrator (MI) is a lightweight, cloud-native integration engine built for microservices architecture. It enables seamless connectivity between APIs, services, data sources, and systems, whether they are cloud-based, SaaS, or legacy systems.</p><p>In simple terms, WSO2 MI helps you:</p><ul><li>Integrate different systems (databases, APIs, files, etc.)</li><li>Automate data flows and business processes</li><li>Deploy integrations easily in cloud-native environments like Docker and Kubernetes etc.</li></ul><h3>Project Overview</h3><p>We’ll build a simple <strong>RESTful data service</strong> that interacts with a MySQL database. The service exposes four endpoints to perform basic <strong>CRUD operations</strong> on an employee table.</p><p>Here’s what the project will do: Retrieve all records or a specific employee by ID, Insert a new employee, Update an existing employee and Remove an existing employee through REST end points.</p><p>By the end of this guide, you will be able to run the Data Service both locally and within a Docker container</p><h3>Setting the Groundwork</h3><p>We’ll use <strong>WSO2 Data Services</strong> to generate REST endpoints directly from the MySQL table. This removes the need for custom API logic in most cases.</p><p>let’s create the Data service by following steps,</p><ol><li>Choose a project name and create a MI project workspace in Visual Studio Code, as illustrated below.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*he9h2WhkeNCWapwksnya6w.png" /></figure><p>2. Select Data service under artifacts and choose a name for the for the data Service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhG-gUKGO4wFCYocylIwsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*boQJnC765zmEWjQ7wePXNg.png" /></figure><p>3. As we are trying to connect with MySQL, you should select RDBMS for the Data source Type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QX6EJzwlB3ISlto1Kjz60A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3hTrEa23bqai-EW0JCr0cA.png" /></figure><p>4. An important step to consider is adding the appropriate JDBC driver version that is compatible with your database. Ensure the connection is configured correctly by providing the valid database name and password.</p><p>Then, test the connection to confirm that it has been successfully established, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhJQHxyUVIXg6J8mRcz9FA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8XC9MALKCA3e36_Qf0JmGg.png" /></figure><p>5. Now that you have successfully created the Data Service, you can proceed to add the necessary resources based on the specific requirements of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G8C26Q0wj48MpJ4Cu5Re6A.png" /></figure><p>I’ve attached the code for RESTDataService.dbs, which you can readily use in your project.</p><pre>&lt;data name=&quot;InsuranceEmployeesService&quot; transports=&quot;http https&quot; serviceType=&quot;data&quot; media-type=&quot;json&quot;&gt;<br>    &lt;config id=&quot;default&quot;&gt;<br>        &lt;property name=&quot;driverClassName&quot;&gt;com.mysql.cj.jdbc.Driver&lt;/property&gt;<br>        &lt;property name=&quot;url&quot;&gt;jdbc:mysql://host.docker.internal:3306/insurance&lt;/property&gt;<br>        &lt;property name=&quot;username&quot;&gt;root&lt;/property&gt;<br>        &lt;property name=&quot;password&quot;&gt;12345&lt;/property&gt;<br>    &lt;/config&gt;<br><br>    &lt;!-- Get All Employees --&gt;<br>    &lt;query id=&quot;getAllEmployees&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;SELECT * FROM employees&lt;/sql&gt;<br>        &lt;result outputType=&quot;json&quot;&gt;{<br>            &quot;Employees&quot;: {<br>                &quot;Employee&quot;: [<br>                    {<br>                        &quot;employee_id&quot;: &quot;$employee_id&quot;,<br>                        &quot;first_name&quot;: &quot;$first_name&quot;,<br>                        &quot;last_name&quot;: &quot;$last_name&quot;,<br>                        &quot;role&quot;: &quot;$role&quot;,<br>                        &quot;email&quot;: &quot;$email&quot;,<br>                        &quot;phone&quot;: &quot;$phone&quot;,<br>                        &quot;created_at&quot;: &quot;$created_at&quot;,<br>                        &quot;address&quot;: &quot;$address&quot;<br>                    }<br>                ]<br>            }<br>        }&lt;/result&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;GET&quot; path=&quot;/employees&quot;&gt;<br>        &lt;call-query href=&quot;getAllEmployees&quot;/&gt;<br>    &lt;/resource&gt;<br><br>    &lt;!-- Get Employee by ID --&gt;<br>    &lt;query id=&quot;getEmployeeById&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;SELECT * FROM employees WHERE employee_id = :employee_id&lt;/sql&gt;<br>        &lt;result outputType=&quot;json&quot;&gt;{<br>            &quot;Employee&quot;: {<br>                &quot;employee_id&quot;: &quot;$employee_id&quot;,<br>                &quot;first_name&quot;: &quot;$first_name&quot;,<br>                &quot;last_name&quot;: &quot;$last_name&quot;,<br>                &quot;role&quot;: &quot;$role&quot;,<br>                &quot;email&quot;: &quot;$email&quot;,<br>                &quot;phone&quot;: &quot;$phone&quot;,<br>                &quot;created_at&quot;: &quot;$created_at&quot;,<br>                &quot;address&quot;: &quot;$address&quot;<br>            }<br>        }&lt;/result&gt;<br>        &lt;param name=&quot;employee_id&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;GET&quot; path=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;call-query href=&quot;getEmployeeById&quot;&gt;<br>            &lt;with-param name=&quot;employee_id&quot; query-param=&quot;employee_id&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br><br><br>    &lt;!-- Insert Employee --&gt;<br>    &lt;query id=&quot;createEmployee&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;<br>            INSERT INTO employees (first_name, last_name, role, email, phone, created_at, address)<br>            VALUES (:first_name, :last_name, :role, :email, :phone, NOW(), :address)<br>        &lt;/sql&gt;<br>        &lt;param name=&quot;first_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;last_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;role&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;email&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;phone&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;address&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;POST&quot; path=&quot;/employee&quot;&gt;<br>        &lt;call-query href=&quot;createEmployee&quot;&gt;<br>            &lt;with-param name=&quot;first_name&quot; query-param=&quot;first_name&quot;/&gt;<br>            &lt;with-param name=&quot;last_name&quot; query-param=&quot;last_name&quot;/&gt;<br>            &lt;with-param name=&quot;role&quot; query-param=&quot;role&quot;/&gt;<br>            &lt;with-param name=&quot;email&quot; query-param=&quot;email&quot;/&gt;<br>            &lt;with-param name=&quot;phone&quot; query-param=&quot;phone&quot;/&gt;<br>            &lt;with-param name=&quot;address&quot; query-param=&quot;address&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br><br>    &lt;!-- Update Employee --&gt;<br>    &lt;query id=&quot;updateEmployee&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;<br>            UPDATE employees<br>            SET first_name = :first_name,<br>                last_name = :last_name,<br>                role = :role,<br>                email = :email,<br>                phone = :phone,<br>                address = :address<br>            WHERE employee_id = :employee_id<br>        &lt;/sql&gt;<br>        &lt;param name=&quot;employee_id&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;first_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;last_name&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;role&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;email&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;phone&quot; sqlType=&quot;STRING&quot;/&gt;<br>        &lt;param name=&quot;address&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;PUT&quot; path=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;call-query href=&quot;updateEmployee&quot;&gt;<br>            &lt;with-param name=&quot;employee_id&quot; query-param=&quot;employee_id&quot;/&gt;<br>            &lt;with-param name=&quot;first_name&quot; query-param=&quot;first_name&quot;/&gt;<br>            &lt;with-param name=&quot;last_name&quot; query-param=&quot;last_name&quot;/&gt;<br>            &lt;with-param name=&quot;role&quot; query-param=&quot;role&quot;/&gt;<br>            &lt;with-param name=&quot;email&quot; query-param=&quot;email&quot;/&gt;<br>            &lt;with-param name=&quot;phone&quot; query-param=&quot;phone&quot;/&gt;<br>            &lt;with-param name=&quot;address&quot; query-param=&quot;address&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br><br>    &lt;!-- Delete Employee --&gt;<br>    &lt;query id=&quot;deleteEmployee&quot; useConfig=&quot;default&quot;&gt;<br>        &lt;sql&gt;DELETE FROM employees WHERE employee_id = :employee_id&lt;/sql&gt;<br>        &lt;param name=&quot;employee_id&quot; sqlType=&quot;STRING&quot;/&gt;<br>    &lt;/query&gt;<br><br>    &lt;resource method=&quot;DELETE&quot; path=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;call-query href=&quot;deleteEmployee&quot;&gt;<br>            &lt;with-param name=&quot;employee_id&quot; query-param=&quot;employee_id&quot;/&gt;<br>        &lt;/call-query&gt;<br>    &lt;/resource&gt;<br>&lt;/data&gt;</pre><p>Similarly, create an API from the artifacts. Below is the code snippet for the API implementation.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;api context=&quot;/employees-api&quot; name=&quot;employees-api&quot; xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;<br>    &lt;!-- Get all employees --&gt;<br>    &lt;resource methods=&quot;GET&quot; uri-template=&quot;/employees&quot;&gt;<br>        &lt;inSequence&gt;<br>            &lt;send&gt;<br>                &lt;endpoint&gt;<br>                    &lt;http method=&quot;GET&quot; uri-template=&quot;http://localhost:8290/services/InsuranceEmployeesService/employees&quot;/&gt;<br>                &lt;/endpoint&gt;<br>            &lt;/send&gt;<br>        &lt;/inSequence&gt;<br>        &lt;outSequence&gt;<br>            &lt;property name=&quot;messageType&quot; scope=&quot;axis2&quot; value=&quot;application/json&quot;/&gt;<br>            &lt;jsontransform&gt;<br>                &lt;property name=&quot;synapse.commons.json.output.autoPrimitive&quot; value=&quot;false&quot;/&gt;<br>            &lt;/jsontransform&gt;<br>            &lt;respond/&gt;<br>        &lt;/outSequence&gt;<br>        &lt;faultSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Error retrieving employees&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;respond/&gt;<br>        &lt;/faultSequence&gt;<br>    &lt;/resource&gt;<br>    &lt;!-- Get employee by ID --&gt;<br>    &lt;resource methods=&quot;GET&quot; uri-template=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;inSequence&gt;<br>            &lt;property name=&quot;uri.var.employee_id&quot; expression=&quot;get-property(&#39;uri.var.employee_id&#39;)&quot;/&gt;<br>            &lt;send&gt;<br>                &lt;endpoint&gt;<br>                    &lt;http method=&quot;GET&quot; uri-template=&quot;http://localhost:8290/services/InsuranceEmployeesService/employee/{uri.var.employee_id}&quot;/&gt;<br>                &lt;/endpoint&gt;<br>            &lt;/send&gt;<br>        &lt;/inSequence&gt;<br>        &lt;outSequence&gt;<br>            &lt;property name=&quot;messageType&quot; scope=&quot;axis2&quot; value=&quot;application/json&quot;/&gt;<br>            &lt;jsontransform&gt;<br>                &lt;property name=&quot;synapse.commons.json.output.autoPrimitive&quot; value=&quot;false&quot;/&gt;<br>            &lt;/jsontransform&gt;<br>            &lt;respond/&gt;<br>        &lt;/outSequence&gt;<br>        &lt;faultSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Error retrieving employee&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;respond/&gt;<br>        &lt;/faultSequence&gt;<br>    &lt;/resource&gt;    &lt;!-- Create employee --&gt;<br>    &lt;resource methods=&quot;POST&quot; uri-template=&quot;/employee&quot;&gt;<br>        &lt;inSequence&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;property name=&quot;ContentType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;property name=&quot;HTTP_METHOD&quot; scope=&quot;axis2&quot; value=&quot;POST&quot;/&gt;<br>            &lt;property name=&quot;uri.var.first_name&quot; expression=&quot;json-eval($.employee.first_name)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.last_name&quot; expression=&quot;json-eval($.employee.last_name)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.role&quot; expression=&quot;json-eval($.employee.role)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.email&quot; expression=&quot;json-eval($.employee.email)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.phone&quot; expression=&quot;json-eval($.employee.phone)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.address&quot; expression=&quot;json-eval($.employee.address)&quot;/&gt;<br>            &lt;send&gt;<br>                &lt;endpoint&gt;<br>                    &lt;http method=&quot;POST&quot; uri-template=&quot;http://localhost:8290/services/InsuranceEmployeesService/employee?employee_id={uri.var.employee_id}&amp;amp;first_name={uri.var.first_name}&amp;amp;last_name={uri.var.last_name}&amp;amp;role={uri.var.role}&amp;amp;email={uri.var.email}&amp;amp;phone={uri.var.phone}&amp;amp;address={uri.var.address}&quot;/&gt;<br>                &lt;/endpoint&gt;<br>            &lt;/send&gt;<br>        &lt;/inSequence&gt;<br>        &lt;outSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;success&quot;, &quot;message&quot;: &quot;Employee Successfully Created!&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;jsontransform&gt;<br>                &lt;property name=&quot;synapse.commons.json.output.autoPrimitive&quot; value=&quot;false&quot;/&gt;<br>            &lt;/jsontransform&gt;<br>            &lt;respond/&gt;<br>        &lt;/outSequence&gt;<br>        &lt;faultSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Error creating employee&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;respond/&gt;<br>        &lt;/faultSequence&gt;<br>    &lt;/resource&gt;    &lt;!-- Update employee --&gt;<br>    &lt;resource methods=&quot;PUT&quot; uri-template=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;inSequence&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;property name=&quot;ContentType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;property name=&quot;HTTP_METHOD&quot; scope=&quot;axis2&quot; value=&quot;PUT&quot;/&gt;<br>            &lt;property name=&quot;uri.var.employee_id&quot; expression=&quot;get-property(&#39;uri.var.employee_id&#39;)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.first_name&quot; expression=&quot;json-eval($.employee.first_name)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.last_name&quot; expression=&quot;json-eval($.employee.last_name)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.role&quot; expression=&quot;json-eval($.employee.role)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.email&quot; expression=&quot;json-eval($.employee.email)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.phone&quot; expression=&quot;json-eval($.employee.phone)&quot;/&gt;<br>            &lt;property name=&quot;uri.var.address&quot; expression=&quot;json-eval($.employee.address)&quot;/&gt;<br>            &lt;send&gt;<br>                &lt;endpoint&gt;<br>                    &lt;http method=&quot;PUT&quot; uri-template=&quot;http://localhost:8290/services/InsuranceEmployeesService/employee/{uri.var.employee_id}?first_name={uri.var.first_name}&amp;amp;last_name={uri.var.last_name}&amp;amp;role={uri.var.role}&amp;amp;email={uri.var.email}&amp;amp;phone={uri.var.phone}&amp;amp;address={uri.var.address}&quot;/&gt;<br>                &lt;/endpoint&gt;<br>            &lt;/send&gt;<br>        &lt;/inSequence&gt;<br>        &lt;outSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;success&quot;, &quot;message&quot;: &quot;Employee Successfully Updated!&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;jsontransform&gt;<br>                &lt;property name=&quot;synapse.commons.json.output.autoPrimitive&quot; value=&quot;false&quot;/&gt;<br>            &lt;/jsontransform&gt;<br>            &lt;respond/&gt;<br>        &lt;/outSequence&gt;<br>        &lt;faultSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Error updating employee&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;respond/&gt;<br>        &lt;/faultSequence&gt;<br>    &lt;/resource&gt;<br>    &lt;!-- Delete employee --&gt;<br>    &lt;resource methods=&quot;DELETE&quot; uri-template=&quot;/employee/{employee_id}&quot;&gt;<br>        &lt;inSequence&gt;<br>            &lt;property name=&quot;uri.var.employee_id&quot; expression=&quot;get-property(&#39;uri.var.employee_id&#39;)&quot;/&gt;<br>            &lt;send&gt;<br>                &lt;endpoint&gt;<br>                    &lt;http method=&quot;DELETE&quot; uri-template=&quot;http://localhost:8290/services/InsuranceEmployeesService/employee/{uri.var.employee_id}&quot;/&gt;<br>                &lt;/endpoint&gt;<br>            &lt;/send&gt;<br>        &lt;/inSequence&gt;<br>        &lt;outSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;success&quot;, &quot;message&quot;: &quot;Employee Successfully Deleted!&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;jsontransform&gt;<br>                &lt;property name=&quot;synapse.commons.json.output.autoPrimitive&quot; value=&quot;false&quot;/&gt;<br>            &lt;/jsontransform&gt;<br>            &lt;respond/&gt;<br>        &lt;/outSequence&gt;<br>        &lt;faultSequence&gt;<br>            &lt;payloadFactory media-type=&quot;json&quot;&gt;<br>                &lt;format&gt;{&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Error deleting employee&quot;}&lt;/format&gt;<br>                &lt;args/&gt;<br>            &lt;/payloadFactory&gt;<br>            &lt;property name=&quot;messageType&quot; value=&quot;application/json&quot; scope=&quot;axis2&quot;/&gt;<br>            &lt;respond/&gt;<br>        &lt;/faultSequence&gt;<br>    &lt;/resource&gt;<br>&lt;/api&gt;</pre><p>With the project successfully created, you can now run it locally by clicking the ‘Run’ option and test the endpoints using Postman to verify the responses. Once confirmed, proceed to export the project as a .CAR file, which will be used later for containerization.</p><h3><strong>Setting Up the Containers</strong></h3><ul><li><strong>Step 1: Prepare the WSO2 MI Server</strong></li></ul><p>Download the MI server and Place the exported .CAR file (Carbon Application) into the following directory:<strong><br></strong> wso2mi-4.4.0/repository/deployment/server/carbonapps/</p><ul><li><strong>Step 2: MySQL Setup</strong></li></ul><p>Create a folder called mysql-scripts and Place your SQL script for table creation and data insertion inside it.</p><pre>CREATE DATABASE IF NOT EXISTS insurance;<br>USE insurance;<br><br>CREATE TABLE employees (<br>    employee_id VARCHAR(10) PRIMARY KEY,<br>    first_name VARCHAR(100),<br>    last_name VARCHAR(100),<br>    role VARCHAR(50),<br>    email VARCHAR(150),<br>    phone VARCHAR(20),<br>    address VARCHAR(255),<br>    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP<br>);<br><br>DELIMITER //<br>CREATE TRIGGER auto_increment_employee_id <br>BEFORE INSERT ON employees<br>FOR EACH ROW<br>BEGIN<br>    DECLARE next_id INT;<br>    SELECT COALESCE(MAX(CAST(SUBSTRING(employee_id, 3) AS UNSIGNED)), 0) + 1 <br>    INTO next_id FROM employees WHERE employee_id REGEXP &#39;^E_[0-9]+&#39;;<br>    SET NEW.employee_id = CONCAT(&#39;E_&#39;, LPAD(next_id, 3, &#39;0&#39;));<br>END;<br>//<br>DELIMITER ;<br><br>INSERT INTO employees VALUES<br>(&#39;E_001&#39;, &#39;Alice&#39;, &#39;Fernando&#39;, &#39;Claims Officer&#39;, &#39;alice@insure.com&#39;, &#39;0771234567&#39;, &#39;123 Colombo Rd&#39;, NOW()),<br>(&#39;E_002&#39;, &#39;Bob&#39;, &#39;Silva&#39;, &#39;Underwriter&#39;, &#39;bob@insure.com&#39;, &#39;0772345678&#39;, &#39;456 Galle Rd&#39;, NOW()),<br>(&#39;E_003&#39;, &#39;Carol&#39;, &#39;Perera&#39;, &#39;Agent&#39;, &#39;carol@insure.com&#39;, &#39;0773456789&#39;, &#39;789 Kandy Rd&#39;, NOW()),<br>(&#39;E_004&#39;, &#39;Dan&#39;, &#39;Rajan&#39;, &#39;Claims Officer&#39;, &#39;dan@insure.com&#39;, &#39;0774567890&#39;, &#39;Trinco Rd&#39;, NOW()),<br>(&#39;E_005&#39;, &#39;Eve&#39;, &#39;Kumaran&#39;, &#39;Auditor&#39;, &#39;eve@insure.com&#39;, &#39;0775678901&#39;, &#39;Anuradhapura&#39;, NOW());</pre><ul><li><strong>Step 3: Docker Compose Configuration</strong></li></ul><p>Write a docker-compose.yml to spin up both MySQL and WSO2 MI containers, Ensure proper volume mounting and port mapping</p><p>Use a shared network for container communication. Refer the below code snippet,</p><pre>version: &#39;3.8&#39;<br><br>services:<br>  mysql:<br>    image: mysql:5.7<br>    container_name: mysql-container<br>    environment:<br>      MYSQL_ROOT_PASSWORD: ******  # Replace with actual root password<br>      MYSQL_DATABASE: insurance    # Replace with your database name<br>    volumes:<br>      - ./mysql-scripts:/docker-entrypoint-initdb.d <br>    ports:<br>      - &quot;3306:3306&quot;<br>    networks:<br>      - mynetwork<br><br><br>  <br>  micro-integrator:<br>    image: openjdk:17<br>    container_name: micro-integrator<br>    working_dir: /home/wso2/MI  # Path to your MI directory inside the container<br>    volumes:<br>      - ./MI:/home/wso2/MI  # Mount your MI directory here<br>    command: bash -c &quot;cd /home/wso2/MI/bin &amp;&amp; ./micro-integrator.sh&quot;<br>    depends_on:<br>      - mysql<br>    ports:<br>      - &quot;8290:8290&quot; <br>      - &quot;8253:8253&quot;<br>      - &quot;9201:9201&quot;<br>      - &quot;9164:9164&quot;<br>    networks:<br>      - mynetwork<br><br>networks:<br>  mynetwork:<br>    driver: bridge</pre><h3><strong>Running the Project</strong></h3><p>Navigate to the directory where the WSO2 Micro Integrator server and docker-compose.yml file are located. Then, use the docker-compose up command to start the container. Ensure that Rancher Desktop is up and running in the background before executing this command.</p><h3>Testing endpoints</h3><p>Once your WSO2 Micro Integrator container is running, you can test the exposed RESTful endpoints using tools like <strong>Postman</strong> or the command-line tool <strong>curl</strong>. Below are the available API operations along with their corresponding endpoints and example payloads.</p><ol><li>GET — Retrieve All Employees</li></ol><p>- <a href="http://localhost:8290/employees-api/employees">http://localhost:8290/employees-api/employees</a></p><p>2. GET — Retrieve a Specific Employee by ID</p><p>-<a href="http://localhost:8290/employees-api/employee/E_001">http://localhost:8290/employees-api/employee/E_001</a></p><p>3. POST — Create a New Employee Record</p><p>-<a href="http://localhost:8290/employees-api/employee">http://localhost:8290/employees-api/employee</a></p><ul><li><strong>Example Request Body (JSON):</strong></li></ul><pre>{<br>    &quot;employee&quot;: {<br>        &quot;first_name&quot;: &quot;John&quot;,<br>        &quot;last_name&quot;: &quot;Doe&quot;,<br>        &quot;role&quot;: &quot;Manager&quot;,<br>        &quot;email&quot;: &quot;nbjhbjh@example.com&quot;,<br>        &quot;phone&quot;: &quot;1234567890&quot;,<br>        &quot;address&quot;: &quot;Galle&quot;<br>    }<br>}</pre><p>4. PUT — Update an Existing Employee Record<br>-<a href="http://localhost:8290/employees-api/employee/E_004">http://localhost:8290/employees-api/employee/E_004</a></p><ul><li><strong>Example Request Body (JSON):</strong></li></ul><pre>{<br>    &quot;employee&quot;: {<br>        &quot;employee_id&quot;: &quot;E_004&quot;,<br>        &quot;first_name&quot;: &quot;Meyu&quot;,<br>        &quot;last_name&quot;: &quot;Doe&quot;,<br>        &quot;role&quot;: &quot;Manager&quot;,<br>        &quot;email&quot;: &quot;ko@example.com&quot;,<br>        &quot;phone&quot;: &quot;1234567890&quot;,<br>        &quot;address&quot;: &quot;Galle&quot;<br>    }<br>}</pre><p>5. DELETE — Remove an Employee Record<br>- <a href="http://localhost:8290/employees-api/employee/E_004">http://localhost:8290/employees-api/employee/E_004</a></p><p>You can use Postman or curl to send these requests and validate that your Micro Integrator service is functioning correctly, both locally and within the Docker container.</p><p>You can find the Postman collection for testing the API endpoints below,</p><pre>{<br> &quot;info&quot;: {<br>  &quot;_postman_id&quot;: &quot;64db259e-8be7-4ebc-b68b-82f5993d6660&quot;,<br>  &quot;name&quot;: &quot;Insurance-Employees&quot;,<br>  &quot;description&quot;: &quot;Postman collection for WSO2 Data Service - InsuranceEmployeesService&quot;,<br>  &quot;schema&quot;: &quot;https://schema.getpostman.com/json/collection/v2.1.0/collection.json&quot;,<br>  &quot;_exporter_id&quot;: &quot;42569940&quot;,<br>  &quot;_collection_link&quot;: &quot;https://no2222-4951.postman.co/workspace/Insurance-Workspace~c25d533d-b800-4000-a468-7b5b3a4c9204/collection/42569940-64db259e-8be7-4ebc-b68b-82f5993d6660?action=share&amp;source=collection_link&amp;creator=42569940&quot;<br> },<br> &quot;item&quot;: [<br>  {<br>   &quot;name&quot;: &quot;Get All Employees&quot;,<br>   &quot;request&quot;: {<br>    &quot;method&quot;: &quot;GET&quot;,<br>    &quot;header&quot;: [<br>     {<br>      &quot;key&quot;: &quot;Accept&quot;,<br>      &quot;value&quot;: &quot;application/json&quot;,<br>      &quot;type&quot;: &quot;text&quot;,<br>      &quot;disabled&quot;: true<br>     }<br>    ],<br>    &quot;url&quot;: {<br>     &quot;raw&quot;: &quot;http://localhost:8290/employees-api/employees&quot;,<br>     &quot;protocol&quot;: &quot;http&quot;,<br>     &quot;host&quot;: [<br>      &quot;localhost&quot;<br>     ],<br>     &quot;port&quot;: &quot;8290&quot;,<br>     &quot;path&quot;: [<br>      &quot;employees-api&quot;,<br>      &quot;employees&quot;<br>     ]<br>    }<br>   },<br>   &quot;response&quot;: []<br>  },<br>  {<br>   &quot;name&quot;: &quot;Get Employee By ID&quot;,<br>   &quot;request&quot;: {<br>    &quot;method&quot;: &quot;GET&quot;,<br>    &quot;header&quot;: [<br>     {<br>      &quot;key&quot;: &quot;Accept&quot;,<br>      &quot;value&quot;: &quot;application/json&quot;,<br>      &quot;type&quot;: &quot;text&quot;,<br>      &quot;disabled&quot;: true<br>     }<br>    ],<br>    &quot;url&quot;: {<br>     &quot;raw&quot;: &quot;http://localhost:8290/employees-api/employee/E_001&quot;,<br>     &quot;protocol&quot;: &quot;http&quot;,<br>     &quot;host&quot;: [<br>      &quot;localhost&quot;<br>     ],<br>     &quot;port&quot;: &quot;8290&quot;,<br>     &quot;path&quot;: [<br>      &quot;employees-api&quot;,<br>      &quot;employee&quot;,<br>      &quot;E_001&quot;<br>     ]<br>    }<br>   },<br>   &quot;response&quot;: []<br>  },<br>  {<br>   &quot;name&quot;: &quot;Create Employee&quot;,<br>   &quot;request&quot;: {<br>    &quot;method&quot;: &quot;POST&quot;,<br>    &quot;header&quot;: [<br>     {<br>      &quot;key&quot;: &quot;Content-Type&quot;,<br>      &quot;value&quot;: &quot;application/json&quot;<br>     },<br>     {<br>      &quot;key&quot;: &quot;Accept&quot;,<br>      &quot;value&quot;: &quot;application/json&quot;,<br>      &quot;type&quot;: &quot;text&quot;,<br>      &quot;disabled&quot;: true<br>     }<br>    ],<br>    &quot;body&quot;: {<br>     &quot;mode&quot;: &quot;raw&quot;,<br>     &quot;raw&quot;: &quot;{\r\n    \&quot;employee\&quot;: {\r\n        \&quot;first_name\&quot;: \&quot;John\&quot;,\r\n        \&quot;last_name\&quot;: \&quot;Doe\&quot;,\r\n        \&quot;role\&quot;: \&quot;Manager\&quot;,\r\n        \&quot;email\&quot;: \&quot;nbjhbjh@example.com\&quot;,\r\n        \&quot;phone\&quot;: \&quot;1234567890\&quot;,\r\n        \&quot;address\&quot;: \&quot;Galle\&quot;\r\n    }\r\n}&quot;,<br>     &quot;options&quot;: {<br>      &quot;raw&quot;: {<br>       &quot;language&quot;: &quot;json&quot;<br>      }<br>     }<br>    },<br>    &quot;url&quot;: {<br>     &quot;raw&quot;: &quot;http://localhost:8290/employees-api/employee&quot;,<br>     &quot;protocol&quot;: &quot;http&quot;,<br>     &quot;host&quot;: [<br>      &quot;localhost&quot;<br>     ],<br>     &quot;port&quot;: &quot;8290&quot;,<br>     &quot;path&quot;: [<br>      &quot;employees-api&quot;,<br>      &quot;employee&quot;<br>     ]<br>    }<br>   },<br>   &quot;response&quot;: []<br>  },<br>  {<br>   &quot;name&quot;: &quot;Update Employee&quot;,<br>   &quot;request&quot;: {<br>    &quot;method&quot;: &quot;PUT&quot;,<br>    &quot;header&quot;: [<br>     {<br>      &quot;key&quot;: &quot;Content-Type&quot;,<br>      &quot;value&quot;: &quot;application/json&quot;<br>     }<br>    ],<br>    &quot;body&quot;: {<br>     &quot;mode&quot;: &quot;raw&quot;,<br>     &quot;raw&quot;: &quot;{\r\n    \&quot;employee\&quot;: {\r\n        \&quot;employee_id\&quot;: \&quot;E_004\&quot;,\r\n        \&quot;first_name\&quot;: \&quot;Meyu\&quot;,\r\n        \&quot;last_name\&quot;: \&quot;Doe\&quot;,\r\n        \&quot;role\&quot;: \&quot;Manager\&quot;,\r\n        \&quot;email\&quot;: \&quot;ko@example.com\&quot;,\r\n        \&quot;phone\&quot;: \&quot;1234567890\&quot;,\r\n        \&quot;address\&quot;: \&quot;Galle\&quot;\r\n    }\r\n}&quot;<br>    },<br>    &quot;url&quot;: {<br>     &quot;raw&quot;: &quot;http://localhost:8290/employees-api/employee/E_004&quot;,<br>     &quot;protocol&quot;: &quot;http&quot;,<br>     &quot;host&quot;: [<br>      &quot;localhost&quot;<br>     ],<br>     &quot;port&quot;: &quot;8290&quot;,<br>     &quot;path&quot;: [<br>      &quot;employees-api&quot;,<br>      &quot;employee&quot;,<br>      &quot;E_004&quot;<br>     ]<br>    }<br>   },<br>   &quot;response&quot;: []<br>  },<br>  {<br>   &quot;name&quot;: &quot;Delete Employee&quot;,<br>   &quot;request&quot;: {<br>    &quot;method&quot;: &quot;DELETE&quot;,<br>    &quot;header&quot;: [],<br>    &quot;url&quot;: {<br>     &quot;raw&quot;: &quot;http://localhost:8290/employees-api/employee/E_004&quot;,<br>     &quot;protocol&quot;: &quot;http&quot;,<br>     &quot;host&quot;: [<br>      &quot;localhost&quot;<br>     ],<br>     &quot;port&quot;: &quot;8290&quot;,<br>     &quot;path&quot;: [<br>      &quot;employees-api&quot;,<br>      &quot;employee&quot;,<br>      &quot;E_004&quot;<br>     ]<br>    }<br>   },<br>   &quot;response&quot;: []<br>  }<br> ]<br>}</pre><h3>Final Thoughts</h3><p>This project is a great starting point for understanding how to:</p><ul><li>Design RESTful services using WSO2 Micro Integrator.</li><li>Use Docker and Docker Compose for deployment.</li><li>Integrate data services with a relational database.</li></ul><p>🔗 <strong>You can find the complete source code and project files here:</strong></p><p><a href="https://github.com/DivyaniCassionPrinston/MI-DataService---Integration-Project">GitHub - DivyaniCassionPrinston/MI-DataService---Integration-Project: MI DataService - Integration Project</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe625af44d65" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>