<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mukul Bindal</title>
    <description>The latest articles on DEV Community by Mukul Bindal (@mukulbindal).</description>
    <link>https://dev.to/mukulbindal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1072509%2Fc89a6559-c2c1-4f51-b349-0626e64af9ae.png</url>
      <title>DEV Community: Mukul Bindal</title>
      <link>https://dev.to/mukulbindal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mukulbindal"/>
    <language>en</language>
    <item>
      <title>Sentiment Analysis using Azure AI</title>
      <dc:creator>Mukul Bindal</dc:creator>
      <pubDate>Mon, 30 Sep 2024 10:35:52 +0000</pubDate>
      <link>https://dev.to/mukulbindal/sentiment-analysis-using-azure-ai-517j</link>
      <guid>https://dev.to/mukulbindal/sentiment-analysis-using-azure-ai-517j</guid>
      <description>&lt;h2&gt;
  
  
  What is Sentiment Analysis?
&lt;/h2&gt;

&lt;p&gt;Sentiment analysis is a process in natural language processing (NLP) used to determine the emotional tone behind a body of text. It helps in understanding the sentiment (positive, negative, or neutral) of user opinions, social media comments, product reviews, etc. Companies leverage sentiment analysis to gauge customer feedback, monitor brand perception, and improve user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Traditional Machine Learning Approach
&lt;/h2&gt;

&lt;p&gt;Traditionally, sentiment analysis involves building machine learning models from scratch. This process requires several key steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Collection:&lt;/strong&gt; Large datasets are needed to train the model. These datasets must be labeled with sentiment classes (positive, negative, or neutral).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feature Extraction:&lt;/strong&gt; Text data is transformed into numerical features through techniques like TF-IDF or word embeddings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Model Training:&lt;/strong&gt; Machine learning models such as logistic regression, Naive Bayes, or deep learning models like LSTMs are trained on the prepared data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Evaluation and Tuning:&lt;/strong&gt; The model needs to be evaluated and fine-tuned regularly for better accuracy.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;However, this approach has its disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;High Computational Resources:&lt;/strong&gt; Building and training models from scratch can be computationally expensive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Need for Large Datasets:&lt;/strong&gt; High-quality, labeled datasets are needed, which can be hard to obtain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time-Consuming:&lt;/strong&gt; The model development process, from data preparation to tuning, is time-intensive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Low Accuracy:&lt;/strong&gt; Without a large dataset and correct model, accuracy is not good and often leads to less reliability.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advantages of Azure AI Over Traditional Approach
&lt;/h2&gt;

&lt;p&gt;Azure AI provides a robust, pre-trained sentiment analysis model as part of its Language Service. Key benefits include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Scalability: Azure AI allows you to scale up your applications without needing your own infrastructure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pre-trained Models: No need for large datasets or model training—Azure’s pre-trained models are ready to use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cost-Effective: By using a cloud-based service, the need for high computational power and resources is minimized.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Faster Time to Market: Azure’s API can be integrated with your application easily, significantly reducing development time.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before using Azure AI for sentiment analysis, you will need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An Azure subscription.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Azure AI Language Service enabled in your account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Familiarity with Python or another programming language.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps to Implement Sentiment Analysis using Azure AI
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Create Azure Language Service
&lt;/h3&gt;

&lt;p&gt;a. Go to the Azure portal and create a Language Service resource.&lt;/p&gt;

&lt;p&gt;b. Select your subscription, resource group, and region.&lt;/p&gt;

&lt;p&gt;c. Once the resource is created, you’ll receive an endpoint and API key, which will be used for API calls.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Install Azure SDK
&lt;/h3&gt;

&lt;p&gt;Install the azure-ai-textanalytics package:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install azure-ai-textanalytics&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Connect to the Service
&lt;/h3&gt;

&lt;p&gt;a. Go to your Language Service Resource &amp;gt; Keys and Endpoints and copy the credentials&lt;/p&gt;

&lt;p&gt;b. Use the API key and endpoint from your Language Service resource to authenticate your requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Send Text for Sentiment Analysis
&lt;/h3&gt;

&lt;p&gt;Pass the raw text you want to analyze to the API for sentiment detection, without any need of preprocessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample Code
&lt;/h2&gt;

&lt;p&gt;Below is an example of how one can use Azure AI services for NLP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env python3

# Import required packages
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

# Add the Key and Endpoint (Should be in env variables)
KEY='YOUR_LANGUAGE_SERVICE_KEY'
ENDPOINT='YOUR_LANGUAGE_SERVICE_ENDPOINT'

# Create a text analytics client
text_analytics_client = TextAnalyticsClient(ENDPOINT, AzureKeyCredential(KEY))

# Load your data
documents = ["I am thrilled to announce that our team has exceeded all our quarterly targets!",
"I was really disappointed with the service at the restaurant last night",
"The meeting is scheduled for 3 PM tomorrow in the main conference room.",
"She couldn’t stop smiling after receiving the surprise gift from her friends.",
"He felt a deep sense of loss when he heard about the passing of his childhood pet."]

# Call the Azure Service to detect sentiment
response = text_analytics_client.analyze_sentiment(documents=documents)

# Print output
for i, resp in enumerate(response):
    print(f"Text: {documents[i]}\t Sentiment: {resp.sentiment}")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Text: I am thrilled to announce that our team has exceeded all our quarterly targets!    Sentiment: positive
Text: I was really disappointed with the service at the restaurant last night    Sentiment: negative
Text: The meeting is scheduled for 3 PM tomorrow in the main conference room.    Sentiment: neutral
Text: She couldn’t stop smiling after receiving the surprise gift from her friends.    Sentiment: positive
Text: He felt a deep sense of loss when he heard about the passing of his childhood pet.     Sentiment: negative
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can observe that this is a much simplified code than the traditional approach and with better accuracy and minimum time investment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Azure AI simplifies sentiment analysis with its pre-trained, ready-to-use models. By removing the complexity of traditional machine learning approaches, Azure allows developers to focus more on delivering value to their applications without worrying about computational resources, data preparation, or model training. This makes sentiment analysis, or any other NLP task faster, scalable, and more accessible.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>azure</category>
    </item>
    <item>
      <title>Understanding HTTP and HTTPS: How They Work and Secure Data Transmission</title>
      <dc:creator>Mukul Bindal</dc:creator>
      <pubDate>Sat, 20 Apr 2024 07:02:30 +0000</pubDate>
      <link>https://dev.to/mukulbindal/understanding-http-and-https-how-they-work-and-secure-data-transmission-15cc</link>
      <guid>https://dev.to/mukulbindal/understanding-http-and-https-how-they-work-and-secure-data-transmission-15cc</guid>
      <description>&lt;p&gt;HTTP (Hypertext Transfer Protocol) and HTTPS (Hypertext Transfer Protocol Secure) are fundamental protocols for transmitting data over the web. They govern how information is exchanged between clients (such as web browsers) and servers. Let's dive into how HTTP and HTTPS work, using examples to illustrate their functionalities and security aspects.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTTP: The Basics
&lt;/h3&gt;

&lt;p&gt;Consider Alice as a user and Bob as a web server. When Alice accesses a website using HTTP, her browser sends a request to Bob's server, asking for specific content, like a web page. Bob's server then responds by sending the requested data back to Alice's browser.&lt;/p&gt;

&lt;p&gt;HTTP operates over port 80 by default and transfers data in plaintext, making it susceptible to interception and tampering. Here's how a typical HTTP scenario might unfold:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alice's Request (HTTP):&lt;/strong&gt;&lt;br&gt;
   Alice's browser sends an HTTP request to Bob's server for a webpage (e.g., &lt;a href="http://example.com"&gt;http://example.com&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bob's Response (HTTP):&lt;/strong&gt;&lt;br&gt;
   Bob's server responds to Alice's request with the requested webpage's content in plaintext.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now here is the catch, suppose Bob wants to transmit a confidential  information that only Alice should receive, he can not do so in this protocol. The request is hopped over multiple routers before it reaches Alice and vice versa for Bob. Any information provided in plain text, is vulnerable to cyber secruity attacks like phishing, man in the middle attack and replay attacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTTPS: Enhancing Security
&lt;/h3&gt;

&lt;p&gt;HTTPS addresses the security vulnerabilities of HTTP by adding an extra layer of encryption using SSL/TLS (Secure Sockets Layer/Transport Layer Security). Let's see how Alice and Bob communicate securely using HTTPS:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alice's Secure Request (HTTPS):&lt;/strong&gt;&lt;br&gt;
   Alice's browser initiates a secure connection with Bob's server by sending an HTTPS request (e.g., &lt;a href="https://example.com"&gt;https://example.com&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SSL/TLS Handshake:&lt;/strong&gt;&lt;br&gt;
   Alice's browser and Bob's server perform an SSL/TLS handshake to establish a secure encrypted connection. This involves exchanging cryptographic keys and verifying the server's identity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Encrypted Data Transfer:&lt;/strong&gt;&lt;br&gt;
   Once the secure connection is established, all data exchanged between Alice's browser and Bob's server is encrypted, ensuring confidentiality and integrity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bob's Secure Response (HTTPS):&lt;/strong&gt;&lt;br&gt;
   Bob's server responds to Alice's HTTPS request with encrypted data, which Alice's browser decrypts for display.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This sounds simple when represented like above. But the main issue is, how do we ensure that the encrypted data is read properly by the receiver? We need a way to exchange the keys securely. If our keys are exposed, this protocol will become no better than simple HTTP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Public key cryptography:
&lt;/h3&gt;

&lt;p&gt;Public key cryptography is a very smart way of encrypting the data. Algorithms like RSA, DSA and Diffie-Hellman algorithms are used for public key cryptography.&lt;/p&gt;

&lt;p&gt;These algorithms are capable for taking the plain text as input and generate two keys - one using which the data is encrypted, other using which we can decrypt the data. These 2 keys are called our public and private keys. Based on our applications, like Digital Signature, Encryption etc, we use them interchangeably.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Exchange in HTTPS
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client Hello:&lt;/strong&gt;&lt;br&gt;
   When Alice's browser initiates an HTTPS connection to Bob's server, it sends a "Client Hello" message. This message includes supported cryptographic algorithms, random data, and other parameters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Server Hello:&lt;/strong&gt;&lt;br&gt;
   Bob's server responds with a "Server Hello" message. This message contains the chosen cryptographic algorithms, a server-generated random value, and the server's SSL/TLS certificate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Certificate Exchange:&lt;/strong&gt;&lt;br&gt;
   The server sends its SSL/TLS certificate to Alice's browser. This certificate contains the server's public key, information about the certificate issuer (Certificate Authority or CA), and the server's domain name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Public Key Encryption:&lt;/strong&gt;&lt;br&gt;
   Alice's browser uses the server's public key from the certificate to encrypt a "pre-master secret" and sends it to the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Master Secret Derivation:&lt;/strong&gt;&lt;br&gt;
   Both Alice's browser and Bob's server use the exchanged pre-master secret and their respective random values to derive a "master secret." This master secret is used for symmetric encryption during the HTTPS session.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Server Identity Verification and Certificate Validation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Certificate Chain Validation:&lt;/strong&gt;&lt;br&gt;
   Alice's browser checks the server's SSL/TLS certificate for validity. This includes verifying the certificate's expiration date, the issuing CA's signature, and ensuring the certificate hasn't been revoked.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Root CA Trust:&lt;/strong&gt;&lt;br&gt;
   Alice's browser validates the server's certificate chain up to a trusted root CA (Certificate Authority) stored in the browser's trust store. If the chain is valid and trusted, the server's identity is considered verified.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hostname Verification:&lt;/strong&gt;&lt;br&gt;
   Alice's browser matches the server's domain name (e.g., example.com) with the domain name listed in the server's certificate (Subject Alternative Name or Common Name field). This ensures that Alice is connected to the intended website.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Certificate Handling and Renewal
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Certificate Issuance:&lt;/strong&gt;&lt;br&gt;
   Bob's server obtains an SSL/TLS certificate from a trusted CA. This certificate includes the server's public key and is digitally signed by the CA to establish its authenticity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Certificate Renewal:&lt;/strong&gt;&lt;br&gt;
   SSL/TLS certificates have expiration dates. Bob's server periodically renews its certificate before expiration to ensure uninterrupted HTTPS service. Renewed certificates undergo the same validation and issuance process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Certificate Revocation:&lt;/strong&gt;&lt;br&gt;
   If a certificate is compromised or no longer valid, it can be revoked by the issuing CA. Alice's browser checks for certificate revocation using Certificate Revocation Lists (CRLs) or Online Certificate Status Protocol (OCSP) to ensure the server's certificate is still valid.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Browser Validation and Secure Connection
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Secure Connection Established:&lt;/strong&gt;&lt;br&gt;
   After successful key exchange, certificate validation, and identity verification, a secure connection is established between Alice's browser and Bob's server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Encrypted Data Transfer:&lt;/strong&gt;&lt;br&gt;
   All data exchanged between Alice's browser and Bob's server during the HTTPS session is encrypted using symmetric encryption keys derived from the master secret.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trust Indicators:&lt;/strong&gt;&lt;br&gt;
   Alice's browser displays trust indicators such as a padlock icon and "https://" in the URL bar, indicating a secure connection. Extended Validation (EV) certificates may display the organization's name for enhanced trust.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Advantages of HTTPS Over HTTP
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Encryption:&lt;/strong&gt; HTTPS encrypts data during transmission, preventing unauthorized access and interception.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Integrity:&lt;/strong&gt; HTTPS ensures that data remains unaltered during transmission, preventing tampering by malicious actors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication:&lt;/strong&gt; HTTPS verifies the identity of the server, protecting against phishing and man-in-the-middle attacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trustworthiness:&lt;/strong&gt; HTTPS builds user trust by indicating a secure connection through the padlock icon in browsers and "https://" in URLs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;HTTPS ensures secure data transmission over the internet by employing strong encryption, server identity verification through SSL/TLS certificates, and rigorous validation processes. Understanding the intricate steps involved in key exchange, certificate handling, and browser validation helps ensure secure and trustworthy web interactions for users like Alice and servers like Bob.&lt;/p&gt;

&lt;p&gt;HTTP and HTTPS are critical protocols for web communication, with HTTPS offering enhanced security through encryption, data integrity, and server authentication. In the digital age, where privacy and security are paramount, HTTPS has become the standard for secure data transmission over the internet. Understanding the differences between HTTP and HTTPS helps users like Alice and servers like Bob ensure secure and reliable web interactions.&lt;/p&gt;

</description>
      <category>http</category>
      <category>https</category>
      <category>web</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Configuring and Using Eureka Discovery</title>
      <dc:creator>Mukul Bindal</dc:creator>
      <pubDate>Sun, 24 Sep 2023 08:51:18 +0000</pubDate>
      <link>https://dev.to/mukulbindal/configuring-and-using-eureka-discovery-3mkb</link>
      <guid>https://dev.to/mukulbindal/configuring-and-using-eureka-discovery-3mkb</guid>
      <description>&lt;p&gt;Configuring and using Eureka Discovery Server in Spring Cloud is a fundamental step in building microservices-based applications. Below is a guide on how to set up and utilize Eureka in your spring boot application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set Up a Spring Boot Project&lt;/strong&gt;&lt;br&gt;
Start by creating a Spring Boot project using your preferred IDE or Spring Initializer (&lt;a href="https://start.spring.io/"&gt;https://start.spring.io/&lt;/a&gt;). Make sure to include the "Eureka Server" and "Eureka Discovery" dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configure Eureka Server&lt;/strong&gt;&lt;br&gt;
In your Spring Boot application, you need to configure it as a Eureka Server. Create a main class and annotate it with &lt;code&gt;@EnableEurekaServer&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.SpringApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.cloud.netflix.eureka.server.EnableEurekaServer&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;
&lt;span class="nd"&gt;@EnableEurekaServer&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EurekaServerApplication&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nc"&gt;SpringApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EurekaServerApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your &lt;code&gt;application.properties&lt;/code&gt; or &lt;code&gt;application.yml&lt;/code&gt;, specify the server port and any other configurations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;server.port=8761&lt;/span&gt;
&lt;span class="s"&gt;spring.application.name=eureka-server&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Configure Eureka Client(s)&lt;/strong&gt;&lt;br&gt;
Now, you'll create one or more Eureka clients, which are your microservices that register with the Eureka Server. In your microservice project(s), add the Eureka Client dependency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.cloud&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-cloud-starter-netflix-eureka-client&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your microservice's &lt;code&gt;application.properties&lt;/code&gt; or &lt;code&gt;application.yml&lt;/code&gt;, specify the Eureka Server's location:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;eureka.client.service-url.default-zone=http://localhost:8761/eureka&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Register Microservices&lt;/strong&gt;&lt;br&gt;
In each of your microservices, annotate the main class with &lt;code&gt;@EnableDiscoveryClient&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.SpringApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.cloud.client.discovery.EnableDiscoveryClient&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;
&lt;span class="nd"&gt;@EnableDiscoveryClient&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;YourMicroserviceApplication&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nc"&gt;SpringApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;YourMicroserviceApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Test Eureka&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start your Eureka Server application.&lt;/li&gt;
&lt;li&gt;Start your microservices (Eureka Clients).&lt;/li&gt;
&lt;li&gt;Access the Eureka Server's dashboard in your browser: &lt;code&gt;http://localhost:8761&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You should see your registered microservices listed in the dashboard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Load Balancing&lt;/strong&gt;&lt;br&gt;
Eureka also provides client-side load balancing. You can use the &lt;code&gt;@LoadBalanced&lt;/code&gt; annotation with your &lt;code&gt;RestTemplate&lt;/code&gt; or &lt;code&gt;WebClient&lt;/code&gt; to make requests to other services registered with Eureka. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.cloud.client.loadbalancer.LoadBalanced&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.context.annotation.Bean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.context.annotation.Configuration&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.client.RestTemplate&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Configuration&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RestTemplateConfig&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nd"&gt;@LoadBalanced&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nd"&gt;@Bean&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;RestTemplate&lt;/span&gt; &lt;span class="nf"&gt;restTemplate&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RestTemplate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example Use Case:&lt;/strong&gt;&lt;br&gt;
Suppose you have a "ProductService" and a "UserService" as microservices. You can use the &lt;code&gt;@LoadBalanced&lt;/code&gt; &lt;code&gt;RestTemplate&lt;/code&gt; to make requests from the "UserService" to the "ProductService" without hardcoding the URL.&lt;/p&gt;

&lt;p&gt;That's a basic guide on how to configure and use Eureka Discovery Server in Spring Cloud. You can extend this architecture to build complex microservices ecosystems with ease.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Data Storage in Cookies</title>
      <dc:creator>Mukul Bindal</dc:creator>
      <pubDate>Thu, 27 Apr 2023 08:53:32 +0000</pubDate>
      <link>https://dev.to/mukulbindal/data-storage-in-cookies-2dbd</link>
      <guid>https://dev.to/mukulbindal/data-storage-in-cookies-2dbd</guid>
      <description>&lt;p&gt;All of us doing web development might have come across the term 'Cookie' once in our journey. In this post, we will try to understand what is cookie exactly and how we can use it in Javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is cookie?
&lt;/h2&gt;

&lt;p&gt;Cookie is just a small string that can be created by the host server and sent to the client (browser). Client can also manipulate it and send it back in the next request.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server uses 'Set-cookie' in header to set the cookie&lt;/li&gt;
&lt;li&gt;Browser uses document.cookie to read it using javascript&lt;/li&gt;
&lt;li&gt;In the next request, browser automatically adds the cookie in the header&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reading Cookie
&lt;/h2&gt;

&lt;p&gt;We can easily read cookie using the document.cookie object. It will return us all the key-value pairs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing Cookie
&lt;/h2&gt;

&lt;p&gt;In javascript, cookie object has built in set method to set the cookie. Cookie can not be so large, most of the browser supports only 4KB as the max size.&lt;/p&gt;

&lt;p&gt;To write the cookie, we can simply use assignment operator:&lt;br&gt;
document.cookie = 'key=value'&lt;/p&gt;

&lt;p&gt;Note that it will append this new key/value pair to the cookie object and it will not overwrite it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cookie Options
&lt;/h2&gt;

&lt;p&gt;Along with each key/value pair, we can pass some 'options' specific to that pair. We need to pass them as ';' separated strings.&lt;/p&gt;

&lt;h1&gt;
  
  
  Example:
&lt;/h1&gt;

&lt;p&gt;document.cookie = 'user=admin;path=/;domain=myapp.com'&lt;/p&gt;

&lt;p&gt;Some of the commonly used options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;path: It is the current page by default, but we can restrict the access to this cookie by setting any different webpage path&lt;/li&gt;
&lt;li&gt;domain: It is the domain in which this cookie is accessible.&lt;/li&gt;
&lt;li&gt;expire, max-age: These options will mark the cookie as expired. &lt;/li&gt;
&lt;li&gt;samesite: This option will prevent from XSRF attack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is XSRF Attack:
&lt;/h2&gt;

&lt;p&gt;XSRF attack, aka Cross Site Request Forgery, is a common attack that uses cookie to perform Impersonation attack. Suppose we are using a site which uses cookie as the authentication method. Since cookies are sent in each request, if we login to our account and click on some third party link, if we do not use proper security, our login token will reach to the third party site which can be malicious. &lt;/p&gt;

&lt;p&gt;To prevent this attack, most frameworks restrict to use XSRF token along with the forms. The samesite=strict option can also be useful to prevent such attacks. But there are better security mechanisms to prevent the XSRF attack nowadays.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deleting a cookie:
&lt;/h2&gt;

&lt;p&gt;We can not directly manipulate the cookie object due to its set methods. To delete a cookie, we can set the expire or max-age option to delete the cookie.&lt;/p&gt;

&lt;h1&gt;
  
  
  Example:
&lt;/h1&gt;

&lt;p&gt;document.cookie = 'user=admin;max-age=-1'&lt;/p&gt;

&lt;h2&gt;
  
  
  Third Party cookie
&lt;/h2&gt;

&lt;p&gt;You might have seen sites that use third party cookies. They ask for our consent before using the third party cookies. But what exactly is third party cookie? &lt;/p&gt;

&lt;p&gt;A third party cookie is basically the browser's ability to send the cookie to third party sites. Browser has the ability to restrict it. But most of the sites use it to collect the data from users, generally to show ads.&lt;/p&gt;

&lt;p&gt;For example, most of the sites use some third party services or functionality. They might request for some Javascript code while loading the page to use their services. Note that that request will consist of some cookie that is from that third party site. Next time we visit the third party site, this cookie will be sent along with our request. We can create many such scenarios here on how those 3rd party sites can use it to collect information on what kind of sites we are visiting and other stuff. &lt;/p&gt;

&lt;p&gt;There is a regulatory in European countries that restrict the sites to use third party cookies without user's permission. This is known as GDPR and this is why sites need to take user's permission. &lt;/p&gt;

&lt;p&gt;This is it in this post. We will try to see more storage types in next post.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
