<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sohel Ravankole on Medium]]></title>
        <description><![CDATA[Stories by Sohel Ravankole on Medium]]></description>
        <link>https://medium.com/@sohel.ravankole?source=rss-c6c955d5c9cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*692eVyv8YKjrpo96INUZcw.jpeg</url>
            <title>Stories by Sohel Ravankole on Medium</title>
            <link>https://medium.com/@sohel.ravankole?source=rss-c6c955d5c9cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:49:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sohel.ravankole/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploy And Run Docker Images on AWS ECS]]></title>
            <link>https://medium.com/clairvoyantblog/deploy-and-run-docker-images-on-aws-ecs-85a17a073281?source=rss-c6c955d5c9cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/85a17a073281</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[application-modernization]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Sohel Ravankole]]></dc:creator>
            <pubDate>Thu, 31 Dec 2020 10:09:29 GMT</pubDate>
            <atom:updated>2021-01-06T12:08:00.891Z</atom:updated>
            <content:encoded><![CDATA[<h4>Read to know more about how we can use AWS to deploy the docker images</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKxJ9OC4IOSBXSEAiVbFiw.png" /><figcaption><a href="https://d1.awsstatic.com/reInvent/re20-pdp-tier1/Mithril/product-page-diagram_Amazon-ECS@2x.0d872eb6fb782ddc733a27d2bb9db795fed71185.png">AWS Elastic Container Service (ECS)</a></figcaption></figure><p>Nowadays, everyone’s leaning towards the cloud. Everybody wants their services and applications to be hosted on a cloud platform to save a lot of costs required for on-prem servers, feasibility, security, availability, scalability, etc. There are different cloud computing service providers out there like Amazon, Google, Heroku, etc. But, in this blog, we are going to focus on <a href="https://aws.amazon.com/what-is-aws/">Amazon Web Services</a> (AWS).</p><p>AWS is the most comprehensive and continuously evolving cloud computing platform provided by Amazon. AWS offers a combination of Platform-as-a-service (PaaS), Infrastructure-as-a-service (IaaS), and Software-as-a-service (SaaS).</p><p>AWS provides a vast range of services/tools, such as:</p><ul><li>Container — ECS, EKS</li><li>Compute — EC2, Lambda</li><li>Database — RDS, DynamoDB</li><li>Storage — S3, EBS, EFS,</li></ul><p>and many more.</p><p>AWS provides a Free Tier to its newly registered customers for one year from the date of account creation. This provides customers the ability to explore and try out different AWS services free of charge up to the specified limits. More details can be found on the <a href="https://aws.amazon.com/free/">AWS Free Tier</a>.</p><p>Based on my experience and learning, I have penned down, in this blog, these steps for anyone looking to deploy docker images/containers on AWS ECS.</p><h3>What Is AWS ECS?</h3><p>Amazon Elastic Container Service (<a href="https://aws.amazon.com/ecs/">Amazon ECS</a>) is a container orchestration/management service similar to Kubernetes, Docker Swarm, etc. It’s a highly scalable and high-performance service that comes with Docker pre-installed. It allows applications/containers to run on top of EC2 hosts.</p><p>Benefits that make customers choose AWS ECS:</p><ul><li>Focus on building and managing applications instead of infrastructure with Capacity Providers</li><li>More secure</li><li>Reliable</li><li>Option to go serverless with Fargate</li><li>Highly scalable</li><li>Optimized for cost</li></ul><p>Following are the different terminologies in ECS that we’ll go through one-by-one in the next sections:</p><ul><li>Cluster</li><li>Task Definition</li><li>Task</li><li>Container Instance</li><li>Service</li></ul><h3>What Is Docker?</h3><p><a href="https://docs.docker.com/get-started/overview/">Docker</a> is an open platform that simplifies the process of developing, building, managing, and running applications in an isolated environment called a container. It provides us the ability to manage our infrastructure in the same ways that we manage our applications. We can reduce the delay between writing the code and running it by taking advantage of its methodologies for shipping, testing, and deploying the code quickly.</p><p>We can use docker for:</p><ul><li>Enabling consistent and faster delivery of your applications</li><li>Enabling responsive deployment and scaling</li><li>Running more workloads on the same hardware</li></ul><h3>Prerequisites</h3><ul><li>Make sure the <a href="https://docs.docker.com/get-docker/">docker</a> is installed</li><li>Make sure the AWS CLI is <a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html">installed</a> and <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html">configured</a></li><li>Ensure you have a basic understanding of docker and AWS like commands. AWS EC2, Security groups, etc.</li><li>Ensure that your application is created using/updated to the latest version of SpringBoot. Here’s the sample application - <a href="https://github.com/sohel-clairvoyant/SpringBoot-Docker-ECS-Example">SpringBoot-Docker-ECS-Example</a></li></ul><h3>Let’s Dive In</h3><p>Now we’re all set to dive directly into the steps; right from creating a docker image to pushing it to AWS ECR and finally deploying to AWS ECS.</p><h3>Step-1: Creating a repository using ECR</h3><p>Amazon Elastic Container Registry (<a href="https://aws.amazon.com/ecr/">Amazon ECR</a>) is a fully managed container registry that makes it easy for us to store, manage, and deploy Docker container images. It provides an ability to save configurations that help us quickly move our images from Development to the Production environment which reduces the overall workloads.</p><p>The following are the steps to create a repository in AWS ECR:</p><ol><li>Go to AWS management console</li><li>Search for ECR</li><li>Select <a href="https://console.aws.amazon.com/ecr/home?region=us-east-1">Elastic Container Registry (ECR)</a></li><li>Hit Create repository</li><li>Provide Repository name</li><li>Leave other options to default</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1asDxgjmfekOnESyQMHPw.png" /><figcaption>1. Repository creation page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_6WMSg59XGFWUza4BYkhcA.png" /><figcaption>2. The repository has been successfully created</figcaption></figure><p>And we’re done. It’s that simple to create a repository!</p><h3>Step-2: Creating a docker image and pushing it to the newly created repository</h3><p>Assuming you have already created/updated an application using/to the latest version of SpringBoot. If not, then don’t worry. I’ve created the sample application - <a href="https://github.com/sohel-clairvoyant/SpringBoot-Docker-ECS-Example">SpringBoot-Docker-ECS-Example</a>.</p><p>Now, let’s create a docker image and push it to our repository. The following are the steps to create a docker image:</p><ol><li>Open terminal/command prompt</li><li>Navigate (cd) to the project folder</li><li>Run to build the docker image. More details on <a href="https://spring.io/guides/gs/spring-boot-docker/">SpringBoot-Docker</a></li></ol><blockquote>$ mvn spring-boot:build-image</blockquote><p>4. Run to list all docker images</p><blockquote>$ docker image ls</blockquote><p>5. Copy the repository &amp; tag id specific to the application and execute the following command to run the app in local:</p><blockquote>$ docker run --tty -p 8080:8080 demo:0.0.1-SNAPSHOT</blockquote><p>6. Now, open a browser and hit <a href="http://localhost:8080/">http://localhost:8080</a> to verify it’s up &amp; running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uNsVgMdxOPRyEVkYQmycrA.png" /><figcaption>3. Application successfully running on local</figcaption></figure><p>We’ve successfully created a docker image. Now let’s authenticate ourselves, tag the image, and push it to the repository.</p><ol><li>Go to AWS ECR panel</li><li>Open the repository</li><li>Click on the <strong>View push commands</strong> located on the top right of the window</li><li>You’ll get a pop up as below with all the push commands. For this exercise, skip the second command as we’ve already created the docker image.</li><li>In the third command, replace the tag id with the one we got after building the image i.e. <strong>demo:0.0.1-SNAPSHOT</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CuxaM-x5JpmooIg_nw9CJg.png" /><figcaption>4. AWS ECR — Push commands</figcaption></figure><p>The first command will retrieve an auth token which will be used to authenticate our docker client and allow it to push the images to the ECR repository. Once it’s done, we have to tag our image (or build if it’s not already done). A <a href="https://docs.docker.com/engine/reference/commandline/tag/">Docker tag</a> is an alias to the ID of an image that looks something like “0e5574283393”. By default, an image is given the latest tag if it’s not provided explicitly. At last, we have to run the docker push command to push the tagged image to our newly created repository.</p><p>For the first time, it’ll take some time to build &amp; deploy the image. Now, you can go to ECR, open the repository, and you’ll see the uploaded image. Let’s copy the image URL as we need it in our next steps.</p><h3>Step-3: Creating ECS Cluster</h3><p>An Amazon <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/clusters.html">ECS cluster</a> is a grouping of container instances running tasks, or services that use the EC2 launch type. Also, if we’re using the capacity providers, we can define a cluster as a logical grouping of capacity providers.</p><p>We can create an ECS cluster as per our requirements/needs. You’ll find all the steps to create an ECS cluster in the following video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fl4VwDDb059E%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dl4VwDDb059E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fl4VwDDb059E%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/be4b553b202f845aba8691ccdc8a3155/href">https://medium.com/media/be4b553b202f845aba8691ccdc8a3155/href</a></iframe><p>A VPC is created by default for a new account, so select the default VPC followed by subnets — select the first one from the drop-down, and the default security group. If we want to allow SSH to EC2 instances, we have to create a <a href="https://us-east-1.console.aws.amazon.com/ec2/v2/home?region=us-east-1#KeyPairs:sort=keyName">key pair</a> and assign/select it while creating the cluster.</p><h3>Step-4: Creating Task Definition</h3><p><strong>Task definition</strong> is a blueprint that describes how docker containers should launch which is similar to an AWS feature called <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/LaunchConfiguration.html">Launch Configuration</a> (an instance configuration template) except it is for a docker container. The definition contains settings like docker image, exposed port, CPU shares, memory requirement, the command to run, and environmental variables.</p><p>Whereas the <strong>task</strong> is a running container with these settings. We can think of it as an instance of a Task Definition and the <strong>container instance</strong> is just an EC2 instance that is part of an ECS Cluster that has docker and the ecs-agent running on it.</p><p>We’ll be using the image URL from AWS ECR while adding the container. The following video will show you the step-by-step process of creating a task definition:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLwVmMLWYXr4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLwVmMLWYXr4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLwVmMLWYXr4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ae2c7af81ea1ac7c643bd9164e5d017/href">https://medium.com/media/4ae2c7af81ea1ac7c643bd9164e5d017/href</a></iframe><p>If you’re creating the task definition for the first time, the <strong>Task execution role</strong> will be created by default.</p><h3>Step-5: Creating ECS Service</h3><p>We can define an<strong> ECS service</strong> as the long-running tasks of the same Task Definition. In other words, the ECS service enables us to run and maintain a specified number of instances simultaneously in an ECS cluster.</p><p>Let’s go through the video to know how to create a service and complete our final step:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-plA7Q-6_0s%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-plA7Q-6_0s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-plA7Q-6_0s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d56c37926de6162336ac0fadc933ec8/href">https://medium.com/media/4d56c37926de6162336ac0fadc933ec8/href</a></iframe><p>Once we create a service, go to clusters and check. There, you’ll see that one task has been created automatically and is in the running state under the Tasks tab with the latest task definition. However, if you want to create a task manually with the desired task definition, you can follow the below steps to do so:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F3-Jt1ppvTEE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D3-Jt1ppvTEE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F3-Jt1ppvTEE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7b1935e260628c6694e4e0de4e451c6/href">https://medium.com/media/b7b1935e260628c6694e4e0de4e451c6/href</a></iframe><p>Try to keep the task memory below 1 GB as in the earlier step we’ve allocated around 1 GB to our ECS cluster. If we assign our task the same or more memory than our cluster, the task will fail to start with the below error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VHv4d6rKVOFUZBUDasKPdQ.png" /><figcaption>9. Error while starting/running task</figcaption></figure><p>And that’s all we have to do to create and deploy the docker images on AWS ECS.</p><h3>We’re All Set</h3><p>On the local machine, we used the localhost URL to access our application. But wait, now we’re running our application on AWS. How can we access our app now?</p><p>It’s pretty simple,</p><ol><li>Go to EC2 instances</li><li>Select and open the details of the instance which just got created</li><li>Copy either Public IPv4 address or DNS</li><li>Open it with port 8080, something similar to what is shown below</li><li>Enjoy!</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xaYZ-NNN9cPpAAwod8E4lQ.png" /><figcaption>10. EC2 instance details</figcaption></figure><p>Wait, something’s not right! We’ve successfully followed all the steps but are still not able to access the address/service, it’s getting timed out. Don’t worry, it’s because of the security groups. A <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html">security group</a> acts as a virtual firewall to control the incoming and outgoing traffic. If you remember from our earlier steps, we selected the default security group which includes an outbound rule that allows all outbound traffic only.</p><p>Let’s create a new security group and allow inbound traffic over ports 22 (SSH) and 80/8080 (HTTP). The following video will help you with the steps:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FvnzeCX5N5Ag%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DvnzeCX5N5Ag&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FvnzeCX5N5Ag%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f118a753e210c12fb61b0abc611f50d9/href">https://medium.com/media/f118a753e210c12fb61b0abc611f50d9/href</a></iframe><p>Once done, it should now be accessible over HTTP. Try hitting the same address and verify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPacEl68oSTnsQjiAj7iew.png" /><figcaption>12. Accessing app through Public IPv4 DNS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZHVxaRQG-UmqKAtiZNAN5g.png" /><figcaption>13. Accessing greetingWithName API through Public IPv4 DNS</figcaption></figure><p>Congratulations! You have successfully set up your first ECS cluster and deployed a docker image on it.</p><h3>Accessing logs</h3><p>We have already configured the logs to be handled by <a href="https://aws.amazon.com/cloudwatch/">CloudWatch</a> in Step-4. The following are the steps to access them:</p><ol><li>Go to <strong>CloudWatch</strong></li><li>Select <strong>Log groups</strong> under <strong>Logs</strong> from the left panel</li><li>Search for the respective log group. In this case, it’s <strong>/ecs/greetings-task-definition</strong></li><li>Select the log stream for the respective task. In this case, it’s <strong>ecs/greetings-container/c53e876aaefa478b8b4317dc0386075a</strong></li><li>And that’s all. You’re now looking at all Log events for the task — <strong>c53e876aaefa478b8b4317dc0386075a</strong>.</li></ol><h3>Conclusion</h3><p>This is it! Now we know all the steps, right from creating a docker image to deploying/running it on the top of a cluster of EC2 instances in AWS ECS.</p><p>There’s one more service/launch type called <a href="https://aws.amazon.com/fargate/">Fargate</a> that you can choose and explore instead of the EC2 launch type. Fargate is a serverless compute engine for containers that can be used to eliminate the need to choose instances and scale cluster capacity. This makes it easy for us to focus on building our applications rather than choosing/setting up all the other things.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85a17a073281" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clairvoyantblog/deploy-and-run-docker-images-on-aws-ecs-85a17a073281">Deploy And Run Docker Images on AWS ECS</a> was originally published in <a href="https://medium.com/clairvoyantblog">Clairvoyant Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intercepting Requests & Responses Using Axios]]></title>
            <link>https://medium.com/clairvoyantblog/intercepting-requests-responses-using-axios-df498b6cab62?source=rss-c6c955d5c9cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/df498b6cab62</guid>
            <category><![CDATA[interceptors]]></category>
            <category><![CDATA[axios]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sohel Ravankole]]></dc:creator>
            <pubDate>Thu, 24 Dec 2020 07:58:00 GMT</pubDate>
            <atom:updated>2020-12-24T07:58:00.591Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick introduction to Axios and one of its robust features - Interceptor</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*NuPc-wv4AqMor-L34WKwjg.png" /><figcaption><a href="https://user-images.githubusercontent.com/8939680/57233883-20344080-6fe5-11e9-8169-1eeb4c782683.png">Intercepting responses and requests with Axios</a></figcaption></figure><p>Banking on <a href="https://clairvoyantsoft.com/contact/">Clairvoyant</a>’s experience working with Axios library and its many features, this blog documents <strong>Interceptor</strong>- one such feature in the library. Read further to know more about Interceptor and how we can set one up using <a href="https://www.npmjs.com/package/axios">Axios</a>.</p><p>Axios is a modern and popular promise-based HTTP client that we can use to perform HTTP requests. It supports all modern browsers, including IE, and works in both browsers (JS clients) &amp; Node.js platform.</p><p>Axios comes with a robust <a href="https://www.npmjs.com/package/axios#features">set of features</a>:</p><ul><li>Offers a wide range of browser support, including the old ones</li><li>Allows users to make XMLHttpRequests from browsers &amp; HTTP requests from Node.js to interact with servers</li><li>Allows request and response interception</li><li>Allows users to set response timeout</li><li>Offers protection against XSRF at client side</li><li>Supports the Promise API</li><li>Allows request cancellation</li><li>Allows request and response data transformation</li><li>Offers automatic transformation for JSON data</li></ul><h3><strong>Installation</strong></h3><blockquote># Using NPM <br> npm install --save axios</blockquote><blockquote># Using Yarn<br>yarn add axios</blockquote><h3><strong>Usage</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a038f781345b11c7c14972e1716bc59/href">https://medium.com/media/4a038f781345b11c7c14972e1716bc59/href</a></iframe><p>For more details on request config &amp; response schema, visit the below links:</p><ul><li>Request config - <a href="https://www.npmjs.com/package/axios#request-config">https://www.npmjs.com/package/axios#request-config</a></li><li>Response schema - <a href="https://www.npmjs.com/package/axios#response-schema">https://www.npmjs.com/package/axios#response-schema</a></li></ul><h3>What Is An Interceptor?</h3><p>In general, an interceptor is nothing but a function that gets called for every single HTTP request made and the response received by your application.</p><p>In the same way, the <a href="https://www.npmjs.com/package/axios#interceptors">Axios interceptor</a> is a function that gets called by Axios to update/transform each request before forwarding it &amp; check/filter the response before returning it. In short, you can intercept the requests or responses before they are handled by then or catch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHVbXpS_PfpTzyjb6J3QUg.png" /><figcaption>Fig. Request and response interception using Axios</figcaption></figure><h3>Setting up Axios interceptors</h3><p>So far, we got to know Axios &amp; its basic application. Now, it’s time to jump to the focal point of this article, i.e. request &amp; response interception.</p><p>The steps to create Axios request &amp; response interceptors are:</p><ol><li>Create a new Axios instance with a custom config</li><li>Create request, response &amp; error handlers</li><li>Configure/make use of request &amp; response interceptors from Axios</li><li>Export the newly created Axios instance to be used in different locations</li></ol><p>The following code will use &amp; explain the above steps:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/719fe556dfc157914994e6aec41d2b00/href">https://medium.com/media/719fe556dfc157914994e6aec41d2b00/href</a></iframe><p>Let’s use this newly created Axios instance in the example from the <strong>usage</strong> section.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94f021578769cc234de6deb239671bfb/href">https://medium.com/media/94f021578769cc234de6deb239671bfb/href</a></iframe><p>Now, whenever we use this customAxios instance, it’ll intercept the requests, add the authorization header &amp; pass the request to the server. And for the response, it’ll take it back from the server, and check for status 401. If it’s 401 then redirect the user to the login page, else forward/return the response.</p><p>If you don’t want to intercept the request &amp; response, you can always make use of Axios instead of customAxios. Refer to the <strong>usage</strong> section for the same.</p><h3>Conclusion</h3><p>This is how we can make use of the Axios interceptor functions to intercept every request, update the request with authorization header, API key, etc. if it’s set up like that, and forward the request. Once the request is resolved, take the response, perform predefined checks/filters if any, and return/forward the response to complete the request made.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df498b6cab62" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clairvoyantblog/intercepting-requests-responses-using-axios-df498b6cab62">Intercepting Requests &amp; Responses Using Axios</a> was originally published in <a href="https://medium.com/clairvoyantblog">Clairvoyant Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>