<?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"><channel><title><![CDATA[Embracing Open Source, Empowering Minds!]]></title><description><![CDATA[Indika Kularathne: Embracing Open Source, Empowering Minds!]]></description><link>https://indika.one</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 21:09:04 GMT</lastBuildDate><atom:link href="https://indika.one/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[JavaScript Strict Mode: Writing Cleaner and Safer Code]]></title><description><![CDATA[Introduction
JavaScript is a versatile and powerful programming language used extensively for web development. However, like any tool, it can lead to unexpected behaviors and errors if not used carefully. That's where JavaScript strict mode comes int...]]></description><link>https://indika.one/javascript-strict-mode-writing-cleaner-and-safer-code</link><guid isPermaLink="true">https://indika.one/javascript-strict-mode-writing-cleaner-and-safer-code</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[strictMode]]></category><category><![CDATA[best practices]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Thu, 28 Sep 2023 06:44:36 GMT</pubDate><content:encoded><![CDATA[<p>Introduction</p>
<p>JavaScript is a versatile and powerful programming language used extensively for web development. However, like any tool, it can lead to unexpected behaviors and errors if not used carefully. That's where JavaScript strict mode comes into play. In this blog post, we'll explore the benefits and use cases of strict mode, and why it's considered a best practice for modern JavaScript development.</p>
<h2 id="heading-what-is-strict-mode">What is Strict Mode?</h2>
<p>Strict mode is a set of rules and restrictions that can be applied to an entire JavaScript file or to a specific function scope. It was introduced in ECMAScript 5 (ES5) to make JavaScript code less error-prone and more secure. When enabled, strict mode enforces a higher level of scrutiny on your code, catching common coding mistakes and preventing potentially problematic behavior.</p>
<h3 id="heading-enabling-strict-mode">Enabling Strict Mode</h3>
<p>To enable strict mode in your JavaScript code, simply add the following directive to the beginning of your script file or function:</p>
<pre><code class="lang-javascript"><span class="hljs-meta">"use strict"</span>;
</code></pre>
<p>Once enabled, strict mode applies to the entire script file or function and its nested functions.</p>
<h2 id="heading-benefits-of-strict-mode">Benefits of Strict Mode</h2>
<h3 id="heading-1-catching-silent-errors">1. Catching Silent Errors</h3>
<p>One of the primary benefits of strict mode is its ability to catch silent errors. In non-strict mode, certain mistakes, like assigning values to undeclared variables, create global variables without any warnings. This can lead to hard-to-debug issues. In strict mode, these actions result in reference errors, making it easier to identify and fix problems.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Non-strict mode</span>
myVariable = <span class="hljs-number">10</span>; <span class="hljs-comment">// Creates a global variable 'myVariable'</span>

<span class="hljs-comment">// Strict mode</span>
<span class="hljs-meta">"use strict"</span>;
myVariable = <span class="hljs-number">10</span>; <span class="hljs-comment">// ReferenceError: myVariable is not defined</span>
</code></pre>
<h3 id="heading-2-preventing-dangerous-features">2. Preventing Dangerous Features</h3>
<p>Strict mode disables potentially problematic features and practices. For example, it disallows the use of the <code>with</code> statement, which can lead to ambiguous code and performance issues. By disallowing these features, strict mode encourages you to write safer and more predictable code.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Non-strict mode</span>
<span class="hljs-keyword">with</span> (<span class="hljs-built_in">document</span>) {
  <span class="hljs-comment">// You can access document properties without prefixing</span>
  <span class="hljs-comment">// e.g., write("Hello, world!");</span>
}

<span class="hljs-comment">// Strict mode</span>
<span class="hljs-meta">"use strict"</span>;
<span class="hljs-keyword">with</span> (<span class="hljs-built_in">document</span>) {
  <span class="hljs-comment">// SyntaxError: Strict mode code may not include a with statement</span>
}
</code></pre>
<h3 id="heading-3-safer-javascript">3. Safer JavaScript</h3>
<p>In strict mode, JavaScript becomes safer by preventing actions like assigning values to read-only global variables (<code>undefined</code>, <code>NaN</code>, <code>Infinity</code>) and using reserved words as variable or function names. This helps you avoid unintentional overwrites and potential security vulnerabilities.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Non-strict mode</span>
<span class="hljs-literal">undefined</span> = <span class="hljs-number">42</span>; <span class="hljs-comment">// No error, but a bad practice</span>

<span class="hljs-comment">// Strict mode</span>
<span class="hljs-meta">"use strict"</span>;
<span class="hljs-literal">undefined</span> = <span class="hljs-number">42</span>; <span class="hljs-comment">// TypeError: Cannot assign to read-only property 'undefined'</span>
</code></pre>
<h3 id="heading-4-improved-performance">4. Improved Performance</h3>
<p>Strict mode code can sometimes be optimized more aggressively by JavaScript engines, leading to potential performance improvements. While the performance gains may vary depending on the code and the engine, using strict mode can contribute to a more efficient application.</p>
<h2 id="heading-when-to-use-strict-mode">When to Use Strict Mode</h2>
<p>Consider using strict mode in the following scenarios:</p>
<ol>
<li><p><strong>All New Code</strong>: Whenever you start a new JavaScript project or write new code, it's a good practice to enable strict mode from the beginning.</p>
</li>
<li><p><strong>Legacy Code</strong>: If you're maintaining or updating an older JavaScript codebase, consider enabling strict mode for new code and gradually migrating existing code to strict mode as you refactor.</p>
</li>
<li><p><strong>Third-Party Libraries</strong>: If you're using third-party JavaScript libraries, enabling strict mode for your code can help isolate potential issues and prevent conflicts.</p>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>JavaScript strict mode is a powerful tool for writing cleaner, safer, and more robust code. By catching silent errors, preventing dangerous features, ensuring safer JavaScript practices, and potentially improving performance, strict mode enhances the overall quality of your codebase. It's a best practice that every JavaScript developer should embrace to build more reliable web applications. So, don't forget to add <code>"use strict";</code> to your JavaScript files and enjoy the benefits of a stricter, safer JavaScript environment.</p>
]]></content:encoded></item><item><title><![CDATA[UTF-8mb4: The Multilingual Savior of Character Encoding]]></title><description><![CDATA[In today's interconnected world, where information flows freely across borders and cultures, it's crucial for technology to bridge linguistic gaps and ensure seamless communication. Character encoding is a fundamental aspect of this endeavor, and UTF...]]></description><link>https://indika.one/utf-8mb4-the-multilingual-savior-of-character-encoding</link><guid isPermaLink="true">https://indika.one/utf-8mb4-the-multilingual-savior-of-character-encoding</guid><category><![CDATA[utf8]]></category><category><![CDATA[utf-8mb4]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Mon, 11 Sep 2023 06:30:35 GMT</pubDate><content:encoded><![CDATA[<p>In today's interconnected world, where information flows freely across borders and cultures, it's crucial for technology to bridge linguistic gaps and ensure seamless communication. Character encoding is a fundamental aspect of this endeavor, and UTF-8mb4 stands out as a versatile and indispensable solution. In this blog post, we'll delve into the world of UTF-8mb4, exploring its significance, evolution, and practical applications.</p>
<h3 id="heading-the-need-for-multilingual-character-encoding">The Need for Multilingual Character Encoding</h3>
<p>Before we dive into UTF-8mb4, let's understand the problem it aims to solve. Historically, character encoding was primarily designed for English and a few other Western languages. This limitation posed significant challenges when dealing with scripts from non-Western languages like Chinese, Japanese, Korean, and various others, often referred to as CJK characters. The original UTF-8 encoding, while revolutionary, couldn't fully accommodate these diverse scripts, leading to the development of UTF-8mb4.</p>
<h3 id="heading-the-birth-of-utf-8mb4">The Birth of UTF-8mb4</h3>
<p>UTF-8mb4, also known as "UTF-8 Multibyte for 4-byte characters," was introduced as an extension of the UTF-8 standard. The "4" in UTF-8mb4 indicates its ability to handle up to four bytes per character, as opposed to the three bytes in standard UTF-8. This extra byte capacity was necessary to accommodate a broader range of characters, making it a perfect fit for the rapidly globalizing digital landscape.</p>
<h3 id="heading-key-features-of-utf-8mb4">Key Features of UTF-8mb4</h3>
<ol>
<li><p><strong>Support for a Wide Range of Characters</strong>: UTF-8mb4 can represent characters from all major scripts, including emoji, mathematical symbols, musical notations, and many others. This versatility makes it ideal for applications requiring multilingual support.</p>
</li>
<li><p><strong>Emoji Compatibility</strong>: With the rise of emojis as a global communication tool, UTF-8mb4 became essential for properly encoding these colorful and expressive symbols. This ensured that emojis would display correctly across various devices and platforms.</p>
</li>
<li><p><strong>Backward Compatibility</strong>: UTF-8mb4 retains full backward compatibility with standard UTF-8, making it a seamless transition for systems and applications already using UTF-8.</p>
</li>
</ol>
<h3 id="heading-practical-applications">Practical Applications</h3>
<ol>
<li><p><strong>Database Management</strong>: UTF-8mb4 is widely used in database management systems to store and retrieve data in multiple languages. This is especially critical for businesses with international reach.</p>
</li>
<li><p><strong>Social Media and Messaging</strong>: Social media platforms, messaging apps, and online forums rely heavily on UTF-8mb4 to ensure that user-generated content, which can include text in multiple languages and emojis, displays correctly.</p>
</li>
<li><p><strong>Content Management Systems</strong>: Websites and content management systems (CMS) use UTF-8mb4 to accommodate user-generated content and ensure that it's correctly displayed to a global audience.</p>
</li>
<li><p><strong>Localization and Internationalization</strong>: Software developers use UTF-8mb4 to enable the localization and internationalization of applications, allowing them to be adapted for different languages and regions.</p>
</li>
</ol>
<h3 id="heading-conclusion">Conclusion</h3>
<p>UTF-8mb4 is a powerful tool that has revolutionized the way we handle character encoding in the digital age. Its ability to handle a vast array of characters, including emojis, mathematical notations, and more, has made it an indispensable component of modern software and communication systems.</p>
<p>As the world continues to become more interconnected and multilingual, UTF-8mb4 will play an even more significant role in ensuring that information flows freely across borders and cultures, breaking down language barriers in the process. It's not just a character encoding; it's a bridge to a more inclusive and connected world.</p>
]]></content:encoded></item><item><title><![CDATA[Exploring REST API Security: Best Practices and Practical Examples]]></title><description><![CDATA[In today's interconnected digital landscape, securing your REST APIs is paramount to safeguarding sensitive data and ensuring the integrity of your applications. REST (Representational State Transfer) APIs play a pivotal role in modern software archi...]]></description><link>https://indika.one/exploring-rest-api-security-best-practices-and-practical-examples</link><guid isPermaLink="true">https://indika.one/exploring-rest-api-security-best-practices-and-practical-examples</guid><category><![CDATA[REST API]]></category><category><![CDATA[Security]]></category><category><![CDATA[api security]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Tue, 20 Dec 2022 11:52:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691585648118/87b24f00-6fd5-4392-abee-256468d013a9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today's interconnected digital landscape, securing your REST APIs is paramount to safeguarding sensitive data and ensuring the integrity of your applications. REST (Representational State Transfer) APIs play a pivotal role in modern software architecture, allowing seamless communication between different services. In this blog post, we will delve into the fundamentals of REST API security, explore best practices, and provide practical examples to help you build robust and secure APIs.</p>
<p><strong>Understanding REST API Security: Fundamentals</strong></p>
<ol>
<li><p><strong>Authentication vs. Authorization:</strong> Authentication verifies the identity of users or systems, while authorization defines what actions they are allowed to perform. Combining both ensures a comprehensive security strategy.</p>
</li>
<li><p><strong>HTTPS Encryption:</strong> Secure your API endpoints by implementing HTTPS encryption. This shields data transmission from eavesdroppers and ensures data integrity.</p>
</li>
<li><p><strong>Token-Based Authentication:</strong> Implement token-based authentication, such as JSON Web Tokens (JWT), to validate users' identity and grant access based on their credentials.</p>
</li>
</ol>
<p><strong>Best Practices for REST API Security:</strong></p>
<ol>
<li><p><strong>Use Strong Authentication Mechanisms:</strong> Employ multi-factor authentication (MFA) or OAuth for enhanced security and user verification.</p>
</li>
<li><p><strong>Role-Based Access Control (RBAC):</strong> Define different user roles and permissions to restrict unauthorized access to specific API resources.</p>
</li>
<li><p><strong>Input Validation:</strong> Sanitize and validate user input to prevent SQL injection, cross-site scripting (XSS), and other security vulnerabilities.</p>
</li>
<li><p><strong>Limit Exposure:</strong> Only expose necessary endpoints, limiting access to sensitive data and functionalities.</p>
</li>
</ol>
<p><strong>Practical Examples:</strong></p>
<ol>
<li><p><strong>JWT Authentication:</strong> Show how to generate, validate, and decode JWT tokens for secure API access. Provide code snippets in your preferred programming language.</p>
</li>
<li><p><strong>OAuth 2.0 Implementation:</strong> Walk through setting up an OAuth 2.0 authorization server and using OAuth tokens for securing API requests.</p>
</li>
<li><p><strong>Rate Limiting and Throttling:</strong> Implement rate limiting to prevent abuse and distribute resources fairly. Discuss tools like Redis and examples of rate limiting configurations.</p>
</li>
<li><p><strong>Securing API Keys:</strong> Demonstrate how to securely manage and store API keys using environment variables or configuration files.</p>
</li>
</ol>
<p><strong>Conclusion:</strong></p>
<p>REST API security is a critical aspect of modern application development. By implementing strong authentication, authorization, encryption, and following best practices, you can ensure your APIs are robust and safeguarded against potential threats. Incorporating practical examples into your security strategy will empower developers to create secure, reliable, and user-friendly APIs that foster trust among users and stakeholders.</p>
<p>Remember, while the examples provided here offer insights, each application's security needs are unique. Continuously assess and adapt your security measures to stay ahead of evolving threats and protect your users' data effectively.</p>
]]></content:encoded></item><item><title><![CDATA[HTTP Response Codes: A Comprehensive Guide with Examples]]></title><description><![CDATA[In the realm of web development, understanding HTTP response codes is essential for building resilient and user-friendly applications. These codes provide valuable insights into the outcome of a client's request and offer a roadmap for handling vario...]]></description><link>https://indika.one/http-response-codes-a-comprehensive-guide-with-examples</link><guid isPermaLink="true">https://indika.one/http-response-codes-a-comprehensive-guide-with-examples</guid><category><![CDATA[http]]></category><category><![CDATA[404 page]]></category><category><![CDATA[402]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Wed, 16 Feb 2022 11:48:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691585689688/935c2a2e-9cad-46b7-b4f2-59f657000cc6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the realm of web development, understanding HTTP response codes is essential for building resilient and user-friendly applications. These codes provide valuable insights into the outcome of a client's request and offer a roadmap for handling various scenarios. In this blog post, we'll take a deep dive into the world of HTTP response codes, decipher their meanings, and provide real-world examples to illustrate their usage.</p>
<p><strong>1. Informational Responses (1xx):</strong> Informational responses signify that the server has received the request and is processing it. These responses don't contain the final requested resource but indicate that the process is underway.</p>
<ul>
<li><strong>100 Continue:</strong> The server acknowledges the request headers and prompts the client to proceed with the request body.</li>
</ul>
<p><strong>2. Successful Responses (2xx):</strong> Successful responses indicate that the client's request was successfully received, understood, and processed.</p>
<ul>
<li><p><strong>200 OK:</strong> The standard response for successful requests, returning requested data in the response body.</p>
</li>
<li><p><strong>201 Created:</strong> Indicates that a new resource has been successfully created as a result of the request.</p>
</li>
</ul>
<p><strong>3. Redirection Messages (3xx):</strong> Redirection messages indicate that further action needs to be taken by the client to complete the request.</p>
<ul>
<li><p><strong>301 Moved Permanently:</strong> The requested resource has been permanently moved to a new location. The client should update its bookmarks.</p>
</li>
<li><p><strong>302 Found (Moved Temporarily):</strong> Similar to 301, but indicates a temporary move.</p>
</li>
</ul>
<p><strong>4. Client Error Responses (4xx):</strong> Client error responses signify that the client's request cannot be fulfilled due to an error on the client's side.</p>
<ul>
<li><p><strong>400 Bad Request:</strong> The server cannot understand the request due to malformed syntax or invalid parameters.</p>
</li>
<li><p><strong>401 Unauthorized:</strong> The client needs to provide valid credentials to access the requested resource.</p>
</li>
<li><p><strong>429 Too Many Requests:</strong> The client has sent too many requests in a given amount of time. The server responds with this code to prevent abuse and ensure fair usage.</p>
</li>
</ul>
<p><strong>5. Server Error Responses (5xx):</strong> Server error responses indicate that the server failed to fulfill a valid request.</p>
<ul>
<li><p><strong>500 Internal Server Error:</strong> A generic error message, often indicating an issue on the server side.</p>
</li>
<li><p><strong>503 Service Unavailable:</strong> The server is temporarily unable to handle the request, usually due to maintenance or overload.</p>
</li>
</ul>
<p><strong>Examples:</strong></p>
<ol>
<li><p>Sending a GET request to retrieve user data:</p>
<ul>
<li><p><strong>Response:</strong> HTTP/1.1 200 OK</p>
</li>
<li><p><strong>Body:</strong> <code>{ "username": "john_doe", "email": "</code><a target="_blank" href="mailto:john@example.com"><code>john@example.com</code></a><code>" }</code></p>
</li>
</ul>
</li>
<li><p>Attempting to create a new user with incomplete data:</p>
<ul>
<li><p><strong>Request:</strong> POST /users</p>
</li>
<li><p><strong>Response:</strong> HTTP/1.1 400 Bad Request</p>
</li>
<li><p><strong>Body:</strong> <code>{ "error": "Incomplete data" }</code></p>
</li>
</ul>
</li>
<li><p>Accessing a resource with insufficient permissions:</p>
<ul>
<li><p><strong>Response:</strong> HTTP/1.1 401 Unauthorized</p>
</li>
<li><p><strong>Body:</strong> <code>{ "error": "Authentication required" }</code></p>
</li>
</ul>
</li>
<li><p>Exceeding rate limits for API requests:</p>
<ul>
<li><p><strong>Response:</strong> HTTP/1.1 429 Too Many Requests</p>
</li>
<li><p><strong>Headers:</strong> <code>Retry-After: 60</code> (The client is advised to wait for 60 seconds before retrying)</p>
</li>
</ul>
</li>
</ol>
<p>In conclusion, HTTP response codes are an integral part of web development, facilitating effective communication between clients and servers. By understanding the meaning behind these codes and using them appropriately, developers can enhance user experiences, troubleshoot errors, and build more robust applications. As you continue your journey in web development, mastering HTTP response codes will undoubtedly be a valuable skill in your toolkit.</p>
]]></content:encoded></item><item><title><![CDATA[JWT (JSON Web Token): A Secure and Flexible Approach to Authentication]]></title><description><![CDATA[In today's interconnected digital landscape, secure authentication mechanisms are paramount to safeguarding user data and maintaining trust in web applications. JSON Web Token (JWT) has emerged as a popular and efficient method for achieving secure a...]]></description><link>https://indika.one/jwt-json-web-token-a-secure-and-flexible-approach-to-authentication</link><guid isPermaLink="true">https://indika.one/jwt-json-web-token-a-secure-and-flexible-approach-to-authentication</guid><category><![CDATA[json]]></category><category><![CDATA[JWT]]></category><category><![CDATA[SSO]]></category><category><![CDATA[APIs]]></category><category><![CDATA[HMACSHA256]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Tue, 08 Jun 2021 13:49:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691585786929/838f95bf-8814-45dd-9b23-4d54c3ea03ff.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today's interconnected digital landscape, secure authentication mechanisms are paramount to safeguarding user data and maintaining trust in web applications. JSON Web Token (JWT) has emerged as a popular and efficient method for achieving secure authentication and authorization. In this blog post, we will explore the concept of JWT, its structure, working principle, and its significance in modern web development.</p>
<h3 id="heading-table-of-contents">Table of Contents:</h3>
<ol>
<li><p>What is JWT?</p>
</li>
<li><p>Anatomy of a JWT</p>
</li>
<li><p>How JWT Works</p>
</li>
<li><p>Advantages of JWT</p>
</li>
<li><p>Practical Applications</p>
</li>
<li><p>Conclusion</p>
</li>
</ol>
<h3 id="heading-1-what-is-jwt">1. What is JWT?</h3>
<p>JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way of transmitting information between parties as a JSON object. It is commonly used to securely transmit information between a client (typically a web browser) and a server, providing a trusted form of authentication and authorization.</p>
<h3 id="heading-2-anatomy-of-a-jwt">2. Anatomy of a JWT:</h3>
<p>A JWT is composed of three parts separated by dots ('.'): Header, Payload, and Signature.</p>
<pre><code class="lang-plaintext">header.payload.signature
</code></pre>
<ol>
<li>Header: The header typically consists of two parts: the type of token (JWT) and the signing algorithm used, such as HMAC SHA256 or RSA.</li>
</ol>
<pre><code class="lang-json">{
  <span class="hljs-attr">"alg"</span>: <span class="hljs-string">"HS256"</span>,
  <span class="hljs-attr">"typ"</span>: <span class="hljs-string">"JWT"</span>
}
</code></pre>
<ol>
<li>Payload: The payload contains the claims (statements) about the user and additional data. Claims are classified as registered, public, and private claims.</li>
</ol>
<pre><code class="lang-json">{
  <span class="hljs-attr">"sub"</span>: <span class="hljs-string">"1234567890"</span>,
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"John Doe"</span>,
  <span class="hljs-attr">"admin"</span>: <span class="hljs-literal">true</span>
}
</code></pre>
<ol>
<li>Signature: To create the signature part, the encoded header, encoded payload, and a secret key are used. The signature ensures the integrity of the token and can verify if it has been tampered with.</li>
</ol>
<pre><code class="lang-plaintext">HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  secretKey
)
</code></pre>
<h3 id="heading-3-how-jwt-works">3. How JWT Works:</h3>
<p>The process of using JWT for authentication typically involves the following steps:</p>
<ol>
<li><p><strong>User Authentication</strong>: When a user logs in or provides authentication credentials, the server verifies the credentials and generates a JWT.</p>
</li>
<li><p><strong>JWT Issuance</strong>: The server creates a JWT, comprising the user's identity and any additional claims, then signs it with a secret key. The JWT is sent back to the client.</p>
</li>
<li><p><strong>JWT Usage</strong>: The client stores the JWT, typically in a cookie or local storage. For each subsequent request to the server, the client includes the JWT in the request headers.</p>
</li>
<li><p><strong>JWT Validation</strong>: The server validates the JWT by verifying the signature and decoding the payload. If the JWT is valid and not expired, the server allows access to the requested resources.</p>
</li>
</ol>
<h3 id="heading-4-advantages-of-jwt">4. Advantages of JWT:</h3>
<p>JWT offers several advantages over traditional session-based authentication methods:</p>
<ul>
<li><p><strong>Stateless</strong>: Since JWTs are self-contained, servers do not need to maintain session data, making them stateless and highly scalable.</p>
</li>
<li><p><strong>Security</strong>: JWTs are signed with a secret key, ensuring data integrity and preventing tampering. Additionally, they can be encrypted for an extra layer of security.</p>
</li>
<li><p><strong>Flexibility</strong>: The payload allows for custom claims, making JWTs flexible and versatile for various application requirements.</p>
</li>
</ul>
<h3 id="heading-5-practical-applications">5. Practical Applications:</h3>
<p>JWT finds applications in various scenarios, including:</p>
<ul>
<li><p><strong>Single Sign-On (SSO)</strong>: JWT allows users to log in once and access multiple applications without requiring multiple logins.</p>
</li>
<li><p><strong>API Authentication</strong>: JWT is commonly used to authenticate API requests, providing a secure and straightforward way to protect sensitive endpoints.</p>
</li>
<li><p><strong>Authorization</strong>: JWT's payload can include user roles and permissions, enabling fine-grained access control.</p>
</li>
</ul>
<h3 id="heading-6-conclusion">6. Conclusion:</h3>
<p>JSON Web Token (JWT) has become a go-to method for secure and efficient authentication in modern web development. Its compactness, flexibility, and security features make it a preferred choice for developers and security experts alike.</p>
<p>By understanding the anatomy of a JWT and its working principle, developers can implement robust and reliable authentication mechanisms that enhance the security of their applications.</p>
<p>So, leverage the power of JWT to secure your applications and enable seamless user experiences while preserving data integrity and trust in your web ecosystem.</p>
<p>Happy coding with JWT!</p>
]]></content:encoded></item><item><title><![CDATA[XSLT Demystified: Transforming XML with Ease - A Practical Guide with Examples]]></title><description><![CDATA[XSLT (Extensible Stylesheet Language Transformations) is a powerful and versatile language used for transforming XML documents into various formats. Whether you're working with data integration, web development, or content management, understanding X...]]></description><link>https://indika.one/xslt-demystified-transforming-xml-with-ease-a-practical-guide-with-examples</link><guid isPermaLink="true">https://indika.one/xslt-demystified-transforming-xml-with-ease-a-practical-guide-with-examples</guid><category><![CDATA[XSLT]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Thu, 10 Dec 2020 12:45:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691070242069/ed38bed3-f83b-4a1c-a4b6-5c3d0a85af34.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>XSLT (Extensible Stylesheet Language Transformations) is a powerful and versatile language used for transforming XML documents into various formats. Whether you're working with data integration, web development, or content management, understanding XSLT can greatly enhance your XML processing capabilities. In this blog post, we will explore the fundamentals of XSLT, its syntax, and provide practical examples to showcase its real-world applications.</p>
<h3 id="heading-table-of-contents">Table of Contents:</h3>
<ol>
<li><p>What is XSLT?</p>
</li>
<li><p>XSLT Basics and Syntax</p>
</li>
<li><p>Practical Examples 3.1. Transforming XML to HTML 3.2. Converting XML Data to CSV 3.3. Applying Conditional Formatting</p>
</li>
<li><p>Conclusion</p>
</li>
</ol>
<h3 id="heading-1-what-is-xslt">1. What is XSLT?</h3>
<p>XSLT, part of the Extensible Stylesheet Language (XSL) family, is a declarative language used to define transformations on XML documents. It enables you to extract data from XML, manipulate it, and generate output in various formats, such as HTML, CSV, or even another XML structure. XSLT is widely supported and is a key component in XML processing and web technologies.</p>
<h3 id="heading-2-xslt-basics-and-syntax">2. XSLT Basics and Syntax:</h3>
<p>Before diving into examples, let's briefly cover some XSLT basics:</p>
<ul>
<li><p><code>&lt;xsl:stylesheet&gt;</code>: The root element of an XSLT document.</p>
</li>
<li><p><code>&lt;xsl:template&gt;</code>: Defines a template for matching elements in the source XML document.</p>
</li>
<li><p><code>&lt;xsl:value-of&gt;</code>: Extracts the value of a selected element or attribute.</p>
</li>
<li><p><code>&lt;xsl:for-each&gt;</code>: Iterates over a set of nodes in the source XML document.</p>
</li>
<li><p><code>&lt;xsl:if&gt;</code>: Implements conditional logic based on a specified condition.</p>
</li>
<li><p><code>&lt;xsl:apply-templates&gt;</code>: Applies a template to the selected nodes.</p>
</li>
</ul>
<h3 id="heading-3-practical-examples">3. Practical Examples:</h3>
<h4 id="heading-31-transforming-xml-to-html">3.1. Transforming XML to HTML:</h4>
<p>Suppose we have an XML document containing a list of books, and we want to transform it into an HTML table.</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- Source XML --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">books</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">book</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>The Great Gatsby<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">author</span>&gt;</span>F. Scott Fitzgerald<span class="hljs-tag">&lt;/<span class="hljs-name">author</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">genre</span>&gt;</span>Classic<span class="hljs-tag">&lt;/<span class="hljs-name">genre</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">book</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- More book entries --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">books</span>&gt;</span>
</code></pre>
<pre><code class="lang-plaintext">&lt;!-- XSLT Transformation --&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="books"&gt;
    &lt;html&gt;
      &lt;body&gt;
        &lt;table&gt;
          &lt;tr&gt;
            &lt;th&gt;Title&lt;/th&gt;
            &lt;th&gt;Author&lt;/th&gt;
            &lt;th&gt;Genre&lt;/th&gt;
          &lt;/tr&gt;
          &lt;xsl:apply-templates/&gt;
        &lt;/table&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="book"&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="author"/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="genre"/&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>
<p>The XSLT transformation will convert the XML data into an HTML table, displaying book titles, authors, and genres.</p>
<h4 id="heading-32-converting-xml-data-to-csv">3.2. Converting XML Data to CSV:</h4>
<p>Suppose we have an XML document containing information about employees, and we want to convert it to a CSV format.</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- Source XML --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">employees</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">employee</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>John Doe<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">department</span>&gt;</span>Engineering<span class="hljs-tag">&lt;/<span class="hljs-name">department</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">salary</span>&gt;</span>50000<span class="hljs-tag">&lt;/<span class="hljs-name">salary</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">employee</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- More employee entries --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">employees</span>&gt;</span>
</code></pre>
<pre><code class="lang-plaintext">&lt;!-- XSLT Transformation --&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="text"/&gt;

  &lt;xsl:template match="employees"&gt;
    &lt;xsl:text&gt;Name,Department,Salary&amp;#xa;&lt;/xsl:text&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="employee"&gt;
    &lt;xsl:value-of select="name"/&gt;&lt;xsl:text&gt;,&lt;/xsl:text&gt;
    &lt;xsl:value-of select="department"/&gt;&lt;xsl:text&gt;,&lt;/xsl:text&gt;
    &lt;xsl:value-of select="salary"/&gt;&lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>
<p>The XSLT transformation will convert the XML data into a CSV format, with each employee's information represented in a separate line.</p>
<h4 id="heading-33-applying-conditional-formatting">3.3. Applying Conditional Formatting:</h4>
<p>Suppose we have an XML document containing product data, and we want to apply conditional formatting to display discounted prices.</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- Source XML --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">products</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">product</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>Widget A<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">price</span>&gt;</span>100<span class="hljs-tag">&lt;/<span class="hljs-name">price</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">discount</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">discount</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">product</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- More product entries --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">products</span>&gt;</span>
</code></pre>
<pre><code class="lang-plaintext">&lt;!-- XSLT Transformation --&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="products"&gt;
    &lt;html&gt;
      &lt;body&gt;
        &lt;xsl:apply-templates/&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="product"&gt;
    &lt;p&gt;
      &lt;xsl:value-of select="name"/&gt;:
      &lt;xsl:choose&gt;
        &lt;xsl:when test="discount='true'"&gt;
          &lt;xsl:value-of select="price * 0.9"/&gt; (10% discount)
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:value-of select="price"/&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/p&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>
<p>The XSLT transformation will display product names with discounted prices if the "discount" element is true; otherwise, it will show the regular prices.</p>
<h3 id="heading-4-conclusion">4. Conclusion:</h3>
<p>XSLT (Extensible Stylesheet Language Transformations) is a powerful language for transforming XML data into various formats, such as HTML, CSV, or other XML structures. Armed with the knowledge of XSLT basics and syntax, you can perform advanced XML processing tasks with ease.</p>
<p>In this blog post, we explored practical examples of transforming XML to HTML, converting XML data to CSV, and applying conditional formatting. These examples showcase the versatility and utility of XSLT in real-world scenarios.</p>
<p>As you delve deeper into XSLT, you'll find that it opens up a world of possibilities for managing and manipulating XML data effectively. So, embrace XSLT and take your XML processing skills to new heights!</p>
<p>Happy transforming with XSLT!</p>
]]></content:encoded></item><item><title><![CDATA[The Power of Regular Expressions (RegEx) - A Practical Guide with Examples]]></title><description><![CDATA[Regular Expressions, commonly known as RegEx, are powerful tools used to match, search, and manipulate text patterns in strings. Whether you are a developer, data analyst, or simply someone dealing with text processing, understanding RegEx can be a g...]]></description><link>https://indika.one/the-power-of-regular-expressions-regex-a-practical-guide-with-examples</link><guid isPermaLink="true">https://indika.one/the-power-of-regular-expressions-regex-a-practical-guide-with-examples</guid><category><![CDATA[Regex]]></category><category><![CDATA[Regular Expressions]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Wed, 24 Jun 2020 07:22:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691046795080/03331c05-deaa-4a83-b95c-5045de4c0e55.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Regular Expressions, commonly known as RegEx, are powerful tools used to match, search, and manipulate text patterns in strings. Whether you are a developer, data analyst, or simply someone dealing with text processing, understanding RegEx can be a game-changer. In this blog post, we'll demystify RegEx, explain its syntax, and provide practical examples to showcase its versatility and usefulness.</p>
<h3 id="heading-table-of-contents">Table of Contents:</h3>
<ol>
<li><p>What is Regular Expression (RegEx)?</p>
</li>
<li><p>RegEx Syntax</p>
</li>
<li><p>Practical Examples 3.1. Matching Dates 3.2. Validating Email Addresses 3.3. Extracting Phone Numbers</p>
</li>
<li><p>Conclusion</p>
</li>
</ol>
<h3 id="heading-1-what-is-regular-expression-regex">1. What is Regular Expression (RegEx)?</h3>
<p>Regular Expression (RegEx) is a sequence of characters that defines a search pattern. It's a powerful tool used in various programming languages and text editors to perform advanced string manipulation. RegEx allows you to match, find, or replace specific patterns within strings, making it an essential skill for text processing tasks.</p>
<h3 id="heading-2-regex-syntax">2. RegEx Syntax:</h3>
<p>Before diving into examples, let's briefly review the basic RegEx syntax:</p>
<ul>
<li><p>Literal Characters: Match characters exactly as they appear.</p>
</li>
<li><p>Metacharacters: Special characters that carry a specific meaning in RegEx, such as '.', '*', '+', '?', '|', '()', '[]', '{}', etc.</p>
</li>
<li><p>Character Classes: Define sets of characters to match, like [a-z], [0-9], [A-Za-z], etc.</p>
</li>
<li><p>Quantifiers: Indicate the number of occurrences of a character or group, such as '*', '+', '?', '{n}', '{n, m}', etc.</p>
</li>
<li><p>Anchors: Specify positions in the string, like '^' (start of the line) and '$' (end of the line).</p>
</li>
<li><p>Groups and Capturing: Parentheses '()' are used to group elements and capture matched substrings.</p>
</li>
</ul>
<h3 id="heading-3-practical-examples">3. Practical Examples:</h3>
<h4 id="heading-31-matching-dates">3.1. Matching Dates:</h4>
<p>Suppose we want to match dates in the format "YYYY-MM-DD".</p>
<pre><code class="lang-plaintext">^\d{4}-\d{2}-\d{2}$
</code></pre>
<ul>
<li><p>Example: "2023-08-15" (Matches)</p>
</li>
<li><p>Example: "23-08-15" (Doesn't Match)</p>
</li>
</ul>
<h4 id="heading-32-validating-email-addresses">3.2. Validating Email Addresses:</h4>
<p>Let's validate email addresses with a simple RegEx pattern.</p>
<pre><code class="lang-plaintext">^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
</code></pre>
<ul>
<li><p>Example: "<a target="_blank" href="mailto:user@example.com">user@example.com</a>" (Matches)</p>
</li>
<li><p>Example: "user@123.45" (Doesn't Match)</p>
</li>
</ul>
<h4 id="heading-33-extracting-phone-numbers">3.3. Extracting Phone Numbers:</h4>
<p>Suppose we want to extract phone numbers in the format "XXX-XXX-XXXX".</p>
<pre><code class="lang-plaintext">\d{3}-\d{3}-\d{4}
</code></pre>
<ul>
<li><p>Example: "Call 555-123-4567 for assistance." (Matches - Extracted: "555-123-4567")</p>
</li>
<li><p>Example: "The number is 123-45-6789." (Doesn't Match)</p>
</li>
</ul>
<h3 id="heading-4-conclusion">4. Conclusion:</h3>
<p>Regular Expressions (RegEx) are powerful tools that enable you to perform advanced text processing with ease. By understanding RegEx syntax and using practical examples like matching dates, validating email addresses, or extracting phone numbers, you can harness the full potential of RegEx in your projects.</p>
<p>Remember, mastering RegEx requires practice, so don't hesitate to experiment and refine your patterns. As you become more proficient with RegEx, you'll find it to be an indispensable skill for efficiently handling text-based tasks in various programming contexts.</p>
<p>So, go ahead, dive into the world of Regular Expressions, and unlock the true power of text manipulation!</p>
<p>Happy coding with RegEx!</p>
]]></content:encoded></item><item><title><![CDATA[Demystifying Apache Synapse Mediators: A Hands-On Guide]]></title><description><![CDATA[Demystifying Apache Synapse Mediators: A Hands-On Guide
Apache Synapse is a versatile and powerful Enterprise Service Bus (ESB) that facilitates seamless integration and communication between different systems and services. One of the key components ...]]></description><link>https://indika.one/demystifying-apache-synapse-mediators-a-hands-on-guide</link><guid isPermaLink="true">https://indika.one/demystifying-apache-synapse-mediators-a-hands-on-guide</guid><category><![CDATA[APIs]]></category><category><![CDATA[esb]]></category><category><![CDATA[#medications]]></category><category><![CDATA[apache synapse]]></category><dc:creator><![CDATA[indika kularathne]]></dc:creator><pubDate>Tue, 01 Aug 2017 04:08:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691038441474/0bb1e799-1b32-4c66-befc-9484a1ee3b6e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Demystifying Apache Synapse Mediators: A Hands-On Guide</p>
<p>Apache Synapse is a versatile and powerful Enterprise Service Bus (ESB) that facilitates seamless integration and communication between different systems and services. One of the key components that make Apache Synapse so adaptable is its Mediators. In this comprehensive blog, we will explore the concept of Mediators, understand their types, and dive into hands-on examples showcasing their practical applications.</p>
<h3 id="heading-table-of-contents">Table of Contents:</h3>
<ol>
<li><p>What are Mediators in Apache Synapse?</p>
</li>
<li><p>Built-in Mediators in Apache Synapse 2.1. Filter Mediator 2.2. Log Mediator 2.3. Callout Mediator 2.4. Enrich Mediator 2.5. Script Mediator</p>
</li>
<li><p>Mediator Sequences 3.1. Creating a Custom Mediator Sequence</p>
</li>
<li><p>Conclusion</p>
</li>
</ol>
<h3 id="heading-1-what-are-mediators-in-apache-synapse">1. What are Mediators in Apache Synapse?</h3>
<p>Mediators are fundamental units of processing within Apache Synapse. They are responsible for modifying, filtering, transforming, and routing messages as they flow through the ESB. Mediators play a vital role in ensuring message integrity, security, and facilitating various integration patterns.</p>
<h3 id="heading-2-built-in-mediators-in-apache-synapse">2. Built-in Mediators in Apache Synapse:</h3>
<p>Apache Synapse offers a rich set of built-in Mediators catering to different integration requirements. Let's explore some of the essential Mediators and their applications:</p>
<h4 id="heading-21-filter-mediator">2.1. Filter Mediator:</h4>
<p>The Filter Mediator allows us to route messages based on specific criteria. It evaluates conditions and determines whether the message should follow a particular path or be discarded.</p>
<p>Hands-on Example: Let's consider an API that receives customer orders. We want to filter out orders with a total amount below $100 to reduce load on the backend system.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">api</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://ws.apache.org/ns/synapse"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"OrderApi"</span> <span class="hljs-attr">context</span>=<span class="hljs-string">"/order"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">resource</span> <span class="hljs-attr">methods</span>=<span class="hljs-string">"POST"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">inSequence</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">source</span>=<span class="hljs-string">"$body//totalAmount"</span> <span class="hljs-attr">regex</span>=<span class="hljs-string">"^(?!100\.00$)\d+\.\d{2}$"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">then</span>&gt;</span>
                    <span class="hljs-comment">&lt;!-- Process the valid order --&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">send</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">endpoint</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">http</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"post"</span> <span class="hljs-attr">uri-template</span>=<span class="hljs-string">"http://backend-api.com/processOrder"</span>/&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">endpoint</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">send</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">then</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">else</span>&gt;</span>
                    <span class="hljs-comment">&lt;!-- Discard the order --&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">log</span> <span class="hljs-attr">level</span>=<span class="hljs-string">"custom"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"OrderStatus"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Rejected"</span>/&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">log</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">else</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">inSequence</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">resource</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">api</span>&gt;</span>
</code></pre>
<p>In this example, the Filter Mediator examines the "totalAmount" element in the incoming order message. If the total amount is not exactly $100.00, it proceeds to process the order by sending it to the backend API. Otherwise, it discards the order and logs the rejection status.</p>
<h4 id="heading-22-log-mediator">2.2. Log Mediator:</h4>
<p>The Log Mediator is a valuable tool for debugging and monitoring. It allows us to log messages and their properties during the message flow.</p>
<p>Hands-on Example: We want to log incoming messages, including the timestamp, request payload, and the source IP address.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">api</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://ws.apache.org/ns/synapse"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"LogApi"</span> <span class="hljs-attr">context</span>=<span class="hljs-string">"/log"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">resource</span> <span class="hljs-attr">methods</span>=<span class="hljs-string">"POST"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">inSequence</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">log</span> <span class="hljs-attr">level</span>=<span class="hljs-string">"full"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"Timestamp"</span> <span class="hljs-attr">expression</span>=<span class="hljs-string">"get-property('SYSTEM_TIME')"</span>/&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"RequestPayload"</span> <span class="hljs-attr">expression</span>=<span class="hljs-string">"$body"</span>/&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"SourceIP"</span> <span class="hljs-attr">expression</span>=<span class="hljs-string">"get-property('axis2', 'REMOTE_ADDR')"</span>/&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">log</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Continue with message processing --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">send</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">inSequence</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">resource</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">api</span>&gt;</span>
</code></pre>
<p>In this example, the Log Mediator records the timestamp, request payload, and source IP address of the incoming message. This information can be used for debugging or monitoring the system's behavior.</p>
<h4 id="heading-23-callout-mediator">2.3. Callout Mediator:</h4>
<p>The Callout Mediator allows us to invoke external services and incorporate their responses into the message flow.</p>
<p>Hands-on Example: Let's create an API that calls an external weather service to enrich the incoming message with weather data before forwarding it to the backend system.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">api</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://ws.apache.org/ns/synapse"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"WeatherApi"</span> <span class="hljs-attr">context</span>=<span class="hljs-string">"/weather"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">resource</span> <span class="hljs-attr">methods</span>=<span class="hljs-string">"POST"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">inSequence</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Call the weather service to get weather data --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">callout</span> <span class="hljs-attr">serviceURL</span>=<span class="hljs-string">"http://weather-api.com/getWeather"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">source-type</span>&gt;</span>envelope<span class="hljs-tag">&lt;/<span class="hljs-name">source-type</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">target-property</span>&gt;</span>weatherResponse<span class="hljs-tag">&lt;/<span class="hljs-name">target-property</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">callout</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Enrich the original message with weather data --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">enrich</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"property"</span> <span class="hljs-attr">property</span>=<span class="hljs-string">"weatherResponse"</span>/&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">target</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"body"</span>/&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">enrich</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Continue with the enriched message --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">send</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">inSequence</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">resource</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">api</span>&gt;</span>
</code></pre>
<p>In this example, the Callout Mediator fetches weather data from an external weather service and stores the response in a property named "weatherResponse." The Enrich Mediator then adds this weather data to the original message before forwarding it to the backend system.</p>
<h4 id="heading-24-enrich-mediator">2.4. Enrich Mediator:</h4>
<p>The Enrich Mediator allows us to add information from external sources to the original message, enriching its content.</p>
<p>Hands-on Example: Suppose we have a service that receives customer information and needs to enrich the message with additional data from a customer database.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">api</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://ws.apache.org/ns/synapse"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"CustomerApi"</span> <span class="hljs-attr">context</span>=<span class="hljs-string">"/customer"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">resource</span> <span class="hljs-attr">methods</span>=<span class="hljs-string">"POST"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">inSequence</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Fetch customer data from the database --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">enrich</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"custom"</span> <span class="hljs-attr">clone</span>=<span class="hljs-string">"true"</span> <span class="hljs-attr">xpath</span>=<span class="hljs-string">"getCustomerData($body//customerId)"</span>/&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">target</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"body"</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"child"</span>/&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">enrich</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Continue with the enriched message --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">send</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">inSequence</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">resource</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">api</span>&gt;</span>
</code></pre>
<p>In this example, the Enrich Mediator invokes a custom function "getCustomerData" that queries the customer database based on the "customerId" extracted from the incoming message. The enriched customer data is then added to the original message before processing it further.</p>
<h4 id="heading-25-script-mediator">2.5. Script Mediator:</h4>
<p>The Script Mediator allows us to write custom scripts (e.g., JavaScript) to manipulate messages based on complex logic.</p>
<p>Hands-on Example: Suppose we want to create a custom API that filters orders based on certain criteria using a JavaScript script.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">api</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://ws.apache.org/ns/synapse"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"CustomOrderApi"</span> <span class="hljs-attr">context</span>=<span class="hljs-string">"/customorder"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">resource</span> <span class="hljs-attr">methods</span>=<span class="hljs-string">"POST"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">inSequence</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Execute the custom JavaScript logic --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"js"</span>&gt;</span><span class="xml">
                &lt;![CDATA[
                    var orderAmount = parseFloat(mc.getProperty('ORDER_AMOUNT'));
                    if (orderAmount &gt;= 500) {
                        mc.setProperty('HIGH_VALUE_ORDER', 'true');
                    } else {
                        mc.setProperty('HIGH_VALUE_ORDER', 'false');
                    }
                ]]&gt;
            </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- Continue with the message processing --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">send</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">inSequence</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">resource</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">api</span>&gt;</span>
</code></pre>
<p>In this example,</p>
<p>the Script Mediator runs a JavaScript code snippet that checks the order amount (stored in the property 'ORDER_AMOUNT') and sets the 'HIGH_VALUE_ORDER' property to 'true' if the order amount is greater than or equal to $500; otherwise, it sets it to 'false.'</p>
<h3 id="heading-3-mediator-sequences">3. Mediator Sequences:</h3>
<p>Mediator Sequences are reusable sets of Mediators that can be applied to message flows. They help in encapsulating common logic and promoting reusability across different services.</p>
<h4 id="heading-31-creating-a-custom-mediator-sequence">3.1. Creating a Custom Mediator Sequence:</h4>
<p>Suppose we want to implement a common authentication sequence for multiple APIs.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">sequence</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://ws.apache.org/ns/synapse"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"AuthSequence"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">header</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"Authorization"</span> <span class="hljs-attr">expression</span>=<span class="hljs-string">"fn:concat('Bearer ', $ctx:jwtToken)"</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">send</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">sequence</span>&gt;</span>
</code></pre>
<p>In this example, we create a sequence called "AuthSequence" that adds an "Authorization" header to the outgoing message with a JWT token (stored in the context variable 'jwtToken'). We can now apply this sequence to any API that requires authentication by referencing it in the API configuration.</p>
<h3 id="heading-conclusion">Conclusion:</h3>
<p>In this blog, we've explored the world of Apache Synapse Mediators and their essential role in message processing. We've covered various built-in Mediators such as Filter, Log, Callout, Enrich, and Script, along with practical examples showcasing their applications.</p>
<p>Apache Synapse Mediators provide a powerful toolkit to handle complex integration scenarios, enabling developers to create robust and flexible ESB solutions. Understanding the different types of Mediators and how to use them effectively will significantly enhance your integration projects with Apache Synapse.</p>
<p>Remember, this blog is just an introduction to Apache Synapse Mediators. To dive deeper and explore more advanced use cases, refer to the official Apache Synapse documentation [<a target="_blank" href="https://synapse.apache.org/userguide/mediators.html">https://synapse.apache.org/userguide/mediators.html</a>].</p>
<p>Happy integrating!</p>
]]></content:encoded></item></channel></rss>