<?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 Jay Ar Onde on Medium]]></title>
        <description><![CDATA[Stories by Jay Ar Onde on Medium]]></description>
        <link>https://medium.com/@JayArOnde?source=rss-185fe2f126f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z0MOrchYRCz8lMbvG_RxwA.jpeg</url>
            <title>Stories by Jay Ar Onde on Medium</title>
            <link>https://medium.com/@JayArOnde?source=rss-185fe2f126f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:35:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JayArOnde/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[Building a Python REST API : Getting started with FastAPI]]></title>
            <link>https://medium.com/@JayArOnde/building-a-python-rest-api-getting-started-with-fastapi-f0e201486b3e?source=rss-185fe2f126f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0e201486b3e</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[fastapi]]></category>
            <dc:creator><![CDATA[Jay Ar Onde]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 15:16:24 GMT</pubDate>
            <atom:updated>2022-03-19T15:16:58.829Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building a Python REST API : Getting started with FastAPI</strong></h3><p>A REST API is an architectural pattern for creating web services. REST is a set of rules that outlines the best practices for sharing data between clients and servers. They use HTTP requests to manipulate data and communicate with web services. REST APIs are stateless, cacheable, and consistent. They’re great for building general-purpose and scalable web applications. The three major Python frameworks are Django, Flask, and FastAPI.</p><p>Today, we’re going to explore FastAPI, an open-source web framework used to build APIs with Python.</p><p>Let’s get started!</p><p><strong>We’ll cover</strong>:</p><ul><li>What is FastAPI?</li><li>Flask vs FastAPI</li><li>FastAPI Hello World</li><li>Basic FastAPI building blocks</li><li>What to learn next</li></ul><h3>What is FastAPI?</h3><p>The official FastAPI website describes FastAPI as a <strong>modern and high-performance web framework for building APIs with Python 3.6+ </strong>based on standard Python type hints. FastAPI is very fast due to its out-of-the-box support of the async feature of Python 3.6+.</p><p>FastAPI was released in 2018, and it was created by Sebastian Ramirez. Ramirez was unhappy with existing frameworks like Flask and DRF, so he created his own framework using tools like Starlette and Pydantic. Now, many big tech companies like Uber, Netflix, and Microsoft are using FastAPI to build their apps.</p><h3>FastAPI features</h3><p>FastAPI has many great features. Let’s take a look at them:</p><ul><li><strong>High-performance</strong>: As the name suggests, FastAPI is <em>fast</em>. It’s considered to be one of the fastest Python frameworks currently available.</li><li><strong>Robust</strong>: You can create production-ready code using automatic interactive documentation.</li><li><strong>Intuitive</strong>: FastAPI was designed to be easy to use and learn. It offers great editor support and documentation.</li><li><strong>Quick to code</strong>: FastAPI increases your developing speed by 200%-300%.</li><li><strong>Fewer bugs</strong>: It reduces around 40% of induced bugs.</li><li><strong>Compatible</strong>: It works well with the open standards for APIS, OpenAPI (previously known as Swagger), and JSON schema.</li><li><strong>Plugins</strong>: You can easily create plugins using dependency injection.</li><li><strong>Type hints</strong>: You can use type hinting for data validation and conversion.</li></ul><h3>Flask vs FastAPI</h3><p>In this section, we’ll explore Flask and FastAPI. We’ll discuss their pros, cons, and use cases.</p><h3>Flask</h3><p>Flask is a <strong>Python microframework</strong>. It comes with ORM, caching, and authentication. It was designed to build web applications using Python. It’s considered to be easy, fast, and scalable.</p><p><strong>Pros</strong></p><p><strong>Flexible</strong>: You can manipulate most aspects of Flask.</p><p><strong>Intuitive</strong>: Flask is great for beginners because of its simplicity.</p><p><strong>Built-in development server</strong>: This built-in functionality, along with its integrated support, allows for seamless unit testing.</p><p><strong>Cons</strong></p><p><strong>No data validation</strong>: With Flask, you can pass any data type. This can cause programs to crash often.</p><p><strong>Time</strong>: It has a single source that handles requests in turns, meaning that it can take some time for requests to be addressed.</p><p><strong>Use cases</strong></p><p>Flask is commonly used for projects such as:</p><ul><li>E-commerce systems</li><li>Social media bots</li><li>Social networks</li><li>Static websites</li></ul><h3>FastAPI</h3><p>FastAPI is a modern, high-performance web framework. It’s used to build web APIs.</p><p><strong>Pros</strong></p><ul><li><strong>Data validation</strong>: It validates your data type even in nested JSON requests.</li><li><strong>Exception handling</strong>: With FastAPI, it’s easy to do exception handling.</li><li><strong>Asynchronous code support</strong>: It supports async code using the async/await Python keywords.</li></ul><p><strong>Cons</strong></p><ul><li><strong>Request validation</strong>: FastAPI uses Pydantic for request validation. This process isn’t always very intuitive, and it sometimes requires you to write your own custom validator.</li><li><strong>Smaller community</strong>: Since the framework is still pretty new, the community is smaller in comparison to other frameworks.</li></ul><p><strong>Use cases</strong></p><p>FastAPI is commonly used for projects such as:</p><ul><li>Internal crisis management</li><li>Deploying machine learning models</li><li>Create accounts, logins, and authentication for web applications</li></ul><h3>FastAPI Hello World</h3><p>Let’s get some practice with FastAPI! We’ll take a look at a simple Hello World! and break down the pieces.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81b56c5cc1421e8ea7f590da40b7039d/href">https://medium.com/media/81b56c5cc1421e8ea7f590da40b7039d/href</a></iframe><p>To start the server, we need to run the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/054ebfc532826be7fac472f87106ac16/href">https://medium.com/media/054ebfc532826be7fac472f87106ac16/href</a></iframe><p>Let’s break this down:</p><ul><li>main: refers to the file name</li><li>app: refers to the object of FastAPI created inside the <a href="http://hello.py/">hello.py</a> file</li><li>--reload: parameter that makes the server restart after the code changes</li></ul><p>Let’s break down our Hello World! code:</p><ul><li><strong>Line 1</strong>: We import FastAPI, which is a Python class that provides all the functionality for the API.</li><li><strong>Line 3</strong>: We create an instance of the class FastAPI and name it app. This is the app referred to by uvicorn in the above command.</li><li><strong>Line 5</strong>: We create a GET path.</li><li><strong>Line 6</strong>: We define the function that will execute whenever someone visits the above path.</li><li><strong>Line 7</strong>: We return a response to the client whenever the route is accessed.</li></ul><h3>Basic FastAPI building blocks</h3><p>Let’s explore some of the building blocks of FastAPI, including path parameters, query parameters, and request bodies.</p><h3>Path parameters</h3><p>Path parameters help <strong>scope the API call down to a single resource</strong>, which means you don’t have to build a body for something as simple as a resource finder.</p><p>These parameters are enclosed in curly brackets {}, and they offer a way for you to <strong>control the representation of specific resources</strong>. They’re placed before the query string and within the path of an endpoint.</p><p>Let’s take a look at how to use them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fc59f1d53f48ea12beedc68783185a5/href">https://medium.com/media/2fc59f1d53f48ea12beedc68783185a5/href</a></iframe><p>The value of the path parameter course_name will be passed to the function read_couse() as the argument course_name.</p><h3>Query parameters</h3><p>Query parameters are <strong>optional</strong>. In FastAPI, function parameters that aren’t declared as part of the path parameters are automatically interpreted as query parameters.</p><p>Let’s look at some sample code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a451026ac1ac65945b3ab8cc05ac996/href">https://medium.com/media/5a451026ac1ac65945b3ab8cc05ac996/href</a></iframe><p>The <em>query </em>is the set of key-value pairs that comes after the question mark ? in a URL, separated by an ampersand &amp;.</p><p>Take a look at the following URL:</p><p><a href="http://localhost:8000/courses/?start=0&amp;end=10">http://localhost:8000/courses/?start=0&amp;end=10</a></p><p>Its query parameters are:</p><p>start with a value of 0 and end with a value of 10.</p><p>In <strong>line 8 </strong>of the code, we pass the two query parameters that our API would expect.</p><h3>Request body</h3><p>A request body is <strong>data sent by the client to your API</strong>. To declare one in FastAPI, we can use Pydantic models.</p><p>Let’s see an example of how we can do this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5950d31ddd72f76856ac86b10ffdc088/href">https://medium.com/media/5950d31ddd72f76856ac86b10ffdc088/href</a></iframe><p>Let’s break this down:</p><ul><li><strong>Lines 1–3</strong>: We import the required packages.</li><li><strong>Line 5</strong>: We declare the request data model.</li><li><strong>Line 11</strong>: We create an instance of theFastAPIclass.</li><li><strong>Line 13</strong>: We create aPOSTpath.</li><li><strong>Line 14</strong>: We add the request data model to the path.</li></ul><h3>What to learn next</h3><p>Congrats on taking your first steps with FastAPI! FastAPI is a lighter web framework for Python. It allows you to build APIs easily, quickly, and efficiently. If you’re interested in web application development, learning FastAPI will put you ahead of the curve. To get comfortable with the framework, we suggest you dive deeper into the framework and work on some projects.</p><p>Some recommended topics to cover next are:</p><ul><li>Parallel processing</li><li>Deploying your API to the cloud using GitHub</li><li>Default and optional parameters</li><li>Etc.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0e201486b3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a REST API with ASP.NET Web API]]></title>
            <link>https://medium.com/@JayArOnde/build-a-rest-api-with-asp-net-web-api-d6cd8be4cb02?source=rss-185fe2f126f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6cd8be4cb02</guid>
            <category><![CDATA[web-api-development]]></category>
            <category><![CDATA[web-api-token]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Jay Ar Onde]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 14:22:58 GMT</pubDate>
            <atom:updated>2022-03-19T14:50:22.327Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you need to build a REST API with ASP.NET Web API? If you’re creating a new API, you should probably create it with .NET Core. But it’s not always possible to use the latest and greatest technologies. If you’re working in an existing ASP.NET 4.x app, or the organization you work for hasn’t approved the use of .NET Core yet, you may need to build an API in .NET Framework 4.x. That is what you will learn here. You’ll also learn how to access your API from another application (for machine-to-machine communication) and prevent unauthorized access to your API.</p><p>As you go, I’ll show you how to implement standard design patterns so it will be easy for other developers to understand and work with your API.</p><p>There are a couple of things you’ll need to work through this tutorial.</p><ul><li>Visual Studio 2017</li><li><a href="https://www.getpostman.com/downloads/">Postman</a>, curl, or a similar tool to manually test your API</li></ul><p>Let’s get started!</p><h3>What is REST</h3><p>REST is the acronym that stands for: Representational State Transfer. REST is an architectural style of distributed system. It is based upon the set of principles that describes how network resources are defined and addressed. These set of principles was first described by “Roy Fielding” in 2000. REST is bigger than Web Services.</p><p>RESTful services uses HTTP (Hyper Text Transfer Protocol) to communicate. REST system interface with external systems as web resources identified by URIs (Uniform Resource Identifiers).</p><h3>Constraints of REST</h3><p>A Restful system should follow the constrains so it can be called Restful. There are 5 and 1 optional constraints of REST.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*86xPIz13lihGzX0TEI03lQ.jpeg" /></figure><h3>HTTP Verbs</h3><p>Http verbs plays a very important role in the Restful Web API. The most common Http verbs are GET, PUT, POST and DELETE and these correspond to CRUD (Create, Read, Update and Delete) operations respectively.</p><p>The following Http Verbs exists:</p><ul><li>Get</li><li>Post</li><li>Put</li><li>Delete</li><li>Trace</li><li>Options</li><li>Connect</li><li>Patch</li></ul><p>I will discuss here the most common used verbs and we will also see that how we can use these verbs in my next articles in which we will perform database operations with the help of the above Http verbs.</p><p>So, the following are the description of most common used Http verbs:</p><p><strong>GET</strong></p><p>As the name specifies, this verb is used to retrieve the data or information. It does not have any other effect except getting data.</p><p><strong>Syntax</strong></p><p><em>[HttpGet]</em></p><p>We can use the above syntax to define the method as a GET method. If we are retrieving the data from the database or displaying the data, then we can use this attribute to get the data.</p><p><strong>Use</strong></p><p>Let’s see an example of a GET method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d688f3490cd8011abda833522417ab5c/href">https://medium.com/media/d688f3490cd8011abda833522417ab5c/href</a></iframe><p>In the above example there is a method named GetInfo which is defined as GET method. ActionName attribute is used to define the name of an action method.</p><p>In the above example there is a method named GetInfo which is defined as GET method. ActionName attribute is used to define the name of an action method.</p><p><strong>Call</strong></p><p><em>http://localhost:56828/api/sample/GetInfo</em></p><p>By the help of above Requested URI, we can get the information. Sample is the controller name.</p><p><strong>POST</strong></p><p>This verb is used to generate or create the resource. For example, If we have to add some information to the database then we must define the method as a POST method. The most common form to submit the data into the POST method is to pass the data into any entity object.</p><p><strong>Syntax</strong></p><p><em>[HttpPost]</em></p><p>We can use the above syntax to define the method as a POST method.</p><p><strong>Use</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3dea692532b79c930723373eb437b27f/href">https://medium.com/media/3dea692532b79c930723373eb437b27f/href</a></iframe><p>In the above example there is a method named PostInfo which is defined as POST method. We have to assign the data to the properties of the entity (Result class).</p><p><strong>PUT</strong></p><p>This verb is used to update the existing resource. For example, If we have to update some information to the database then we can define the method as a PUT method. We can send the data in the form of object as well as in a parameter too.</p><p><strong>Syntax</strong></p><p><em>[HttpPut]</em></p><p>We can use the above syntax to define the method as a PUT method.</p><p><strong>Use</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/533daf83529e7a4547ea4e5dc933810f/href">https://medium.com/media/533daf83529e7a4547ea4e5dc933810f/href</a></iframe><p>In the above example there is a method as named UpdateInfo which is defined as PUT method. We can assign the id to update the info.</p><p><strong>DELETE</strong></p><p>This verb is used to delete the existing resource. For example, If we have to delete some information to the database then we can define the method as a DELETE method. We can send the data in the form of object as well as in a parameter too.</p><p><strong>Syntax</strong></p><p><em>[HttpDelete]</em></p><p>We can use the above syntax to define the method as a DELETE method.</p><p><strong>Use</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d72e63396682321eee4c6ed61b3cba81/href">https://medium.com/media/d72e63396682321eee4c6ed61b3cba81/href</a></iframe><p>n the above example there is a method named DeleteInfo which is defined as DELETE method. We can assign the id to delete the info.</p><p><strong>Demo</strong></p><p>In the above section you have learned all the basics of RESTful architecture and Web API. Now, in this section we will create the demo application in which we will perform the database operations from the ASP.NET Web API Application.</p><p><strong>Prerequisites</strong></p><p>If you want to create the demo then you must have Visual Studio 2012 or later version to do this. I am using here Visual Studio 2015.</p><p><strong>Getting Started</strong></p><p>Let’s create an ASP.NET Web API app in which we will perform the CRUD operations and later we will publish it into the Azure API. Now, just follow the procedure below to create the application.</p><h3>Creating Web API Application</h3><p>In this section, we will create the ASP.NET Web API application by following the steps below:</p><p><strong>Step 1: </strong>Open the Visual Studio as an Administrator and click on “New Project”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*aq0Koc1IOJYYDGRhO17a_A.jpeg" /></figure><p><strong>Step 2: </strong>Select the <strong>Web </strong>tab from the left pane and then select <strong>ASP.NET Web Application </strong>to create the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*PxkB7XtsbbuKmSRR2wPzxg.jpeg" /></figure><p><strong>Step 3: </strong>In the next ASP.NET wizard select the <strong>Web API </strong>Project Template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*9n94Z5wKXON6Nt_RnpXyDQ.jpeg" /></figure><p>Now, Web API application is created successfully.</p><p><strong>Perform Database Operations</strong></p><p>In this section, we’ll perform database operation in which we will create the stored procedures to perform CRUD operations. I have created the database and tables with the record and stored procedures too. You can create the whole database from the following script or you can create your own database records. So, just follow the steps below:</p><p><strong>Step 1: </strong>Just create the database from the following script:</p><p><em>CREATE DATABASE [Cricketer]</em></p><p><strong>Step 2: </strong>Now from the following script the whole database is created with the tables and records and stored procs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aeb8d785a3facb389525d4e538f8defb/href">https://medium.com/media/aeb8d785a3facb389525d4e538f8defb/href</a></iframe><p><strong>Perform CRUD Operations</strong></p><p>In this section we will add new projects to associate the database with the Web API application. So, start with the following steps:</p><p><strong>Step 1: </strong>Just add a new Solution Folder in your application named “Models”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*RBtO2feV7NCjFA_Ir6FudQ.jpeg" /></figure><p><strong>Step 2: </strong>Add a “<strong>New Project”</strong> in the <strong>Models </strong>folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*B_gx4h8NvjpXBzaEg8-cjw.jpeg" /></figure><p><strong>Step 3: </strong>Select <strong>Class Library </strong>template to add a new project and name it “<strong>BestCricketers.Models”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*vYAz0ce0qBE3PBr5DW0iBQ.jpeg" /></figure><p><strong>Step 4: </strong>Add a new class named “CricketerProfile” and replace the code with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/327b99415710218af70ceba41fa4f0bf/href">https://medium.com/media/327b99415710218af70ceba41fa4f0bf/href</a></iframe><p><strong>Step 5: </strong>Now add another Solution Folder named “Infrastructure” and add a new project named “BestCricketers.Core”. Add two new folders “BL” and “DAL” in this project.</p><p><strong>Step 6: </strong>Now add “Enterprise Library” Nuget Package</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*ufoezX0SyXFwuAxUO26chw.jpeg" /></figure><p><strong>Step 7: </strong>Add a new class “CricketerDAL” in the DAL folder and replace the code with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36b8c4d63892af11e2e6fb7b4ff75f6c/href">https://medium.com/media/36b8c4d63892af11e2e6fb7b4ff75f6c/href</a></iframe><p><strong>Step 8: </strong>Add a new class “CricketerBL” in the BL folder and replace the code with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a6dd073eb42a01bd4be71fdcff3f707/href">https://medium.com/media/2a6dd073eb42a01bd4be71fdcff3f707/href</a></iframe><p>Now our all methods are ready to perform operations.</p><p><strong>Creating Web API</strong></p><p>In this section, we will work on the ASP.NET Web API application. We will add the new Empty Web API Controller in which we will create some methods to call the CricketerBL class for performing the CRUD operations.</p><p>So, let‚Äôs begin with the following procedure:</p><p><strong>Step 1: </strong>At first, in the API project, right click on the <strong>Controllers </strong>folder and goto Add, then click Controller,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*O9L6ReNecQN1pb4vMxwExw.jpeg" /></figure><p><strong>Step 2: </strong>Select the “<strong>Web API 2 Controller — Empty”</strong> in the next wizard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*7gE_WBYqQEzStX7q_oZQVQ.jpeg" /></figure><p><strong>Figure 9: </strong>Add Scaffold Wizard</p><p><strong>Step 3: </strong>Now enter the controller name as “<strong>CricketersController”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*GtzZZbgJLzl94TsxA-wG-g.jpeg" /></figure><p><strong>Figure 10: </strong>Adding Controller</p><p><strong>Step 4: </strong>Add the following connection string in the ‚ “&lt;ConnectionStrings&gt;” tab in your “Web.config” file of the API project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5583876f1220242a497add3465c4c521/href">https://medium.com/media/5583876f1220242a497add3465c4c521/href</a></iframe><p><strong>Step 5: </strong>Now we will create methods and associate the Http verbs with them. As I said earlier, we will use the most common used verbs in here. So, start with the following sections:</p><p><strong>Note:</strong></p><p>Add the references of Core and Models project into the API project before adding methods in the API Controller.</p><p><strong>GET</strong></p><p>We will create two types of GET methods in here. In first method we will get the list of Cricketers and in the second method we will pass the CricketerId to get the cricketer details.</p><p>Now add the two GET methods with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea428c8016ed65e915c83bf9af757fc8/href">https://medium.com/media/ea428c8016ed65e915c83bf9af757fc8/href</a></iframe><p><strong>Application Execution</strong></p><p>We have successfully created the Web API Controller. Now we will run this application and call our GET methods. We will use POSTMAN to call the GET methods which is easy to use. We can use the Fiddler too.</p><p>You can get the POSTMAN from here.</p><p><strong>Step 1: </strong>Debug the application.</p><p><strong>Step 2: </strong>Now open the POSTMAN and at first copy the url from the browser and use that url as I used in the following screenshot:</p><p><strong>Call Url: </strong><em>http://localhost:64016/api/Cricketers/GetCricketerList</em>,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*2KXSNGF1kNDurw_1DJxXEg.jpeg" /></figure><p><strong>Get Call with Parameter</strong></p><p><strong>Call Url: </strong><em>http://localhost:64016/api/Cricketers/GetCricketerInfoById?Cricketerid=1</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*eNWS5verYBN-eGCfkS6lGw.jpeg" /></figure><p>Now add the following three methods in the controller with which we can checkout the POST, PUT and DELETE methods :</p><p><strong>POST</strong></p><p>In this call, all the data will be send as an object. In POST call, data should be passed in the form of object and sometimes it depends on the condition and you can send the data in the form of FormData.</p><p>Here, I am sending the data in the form of object. So, let’s create the method for POST call with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e040b73241fdcf95bf0a842ad6b66ca/href">https://medium.com/media/4e040b73241fdcf95bf0a842ad6b66ca/href</a></iframe><p><strong>Step 3: </strong>Now open the POSTMAN and call the following <strong>url:</strong></p><p><em>http://localhost:64016/api/Cricketers/AddCricketerInfo</em></p><p>At first add the Header as in the following screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*lvL_wqMyGRgC-98Tf4sHGg.jpeg" /></figure><p>Now click on <strong>Send</strong>,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Bzo0IaGUD5wVVq0Qr_YpWQ.jpeg" /></figure><p>In the above figure you can see your api is showing the response.</p><p><strong>PUT</strong></p><p>In this method we will add the method defined as HttpPut verb with which we can update the data. So, add the following code in the Controller:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eec022291c530bb31fc507acc9dc5955/href">https://medium.com/media/eec022291c530bb31fc507acc9dc5955/href</a></iframe><p><strong>Step 4: </strong>Now open the POSTMAN and call the following url:</p><p><em>http://localhost:64016/api/Cricketers/UpdateCricketerInfo</em></p><p>Now change the HttpVerb to PUT and click on send after defining the updating values as per the following screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*UDmnBqFRrMKH5reCvEjFZQ.jpeg" /></figure><p>In the above screenshot you can that see that record is successfully updated.</p><p><strong>DELETE</strong></p><p>In this method we will delete the CricketerInfo from the database. So we will create the method for deleting info and define it as HttpDelete. Add the following code in the Controller:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbb57943b5a0983fe766bdbc495979bf/href">https://medium.com/media/cbb57943b5a0983fe766bdbc495979bf/href</a></iframe><p><strong>Step 5: </strong>Now open the POSTMAN and call the following url:</p><p><em>http://localhost:64016/api/Cricketers/DeleteCricketerInfo?CricketerId=6</em></p><p>Now change the HttpVerb to DELETE and click on send as per the following screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*JT1NyrbzwJTBeOP-lbiZtA.jpeg" /></figure><p>That‚Äôs it. We have successfully created a Web API Controller in which we have used the most commonly used methods (GET, PUT, POST and DELETE).</p><p><strong>Summary</strong></p><p>So far this article introduces you with the RESTful architecture of Web API and with the help of this article you can get the basic idea of ASP.NET Web API. You can learn the basic objective of creating GET, PUT, POST, DELETE methods and how to call these methods from POSTMAN. In the next article we will play with some advance features of Web API Management. Thanks for reading the article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6cd8be4cb02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Microservices Application Using Spring Boot]]></title>
            <link>https://medium.com/@JayArOnde/building-microservices-application-using-spring-boot-3da3769c7d41?source=rss-185fe2f126f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3da3769c7d41</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Jay Ar Onde]]></dc:creator>
            <pubDate>Mon, 14 Mar 2022 02:29:44 GMT</pubDate>
            <atom:updated>2022-03-14T02:47:14.059Z</atom:updated>
            <content:encoded><![CDATA[<p>With the advent of cloud computing &amp; containerization, microservices has taken the world by storm. Organizations are hunting for professional with <strong>Microservices Architecture Training</strong>. In the previous <strong>blog</strong>, you must have learned how to setup and run Spring Boot using Eclipse IDE and CLI. Now in this Spring Boot Microservices blog, let me show how we can create <strong>Microservices Application </strong>for <strong>Top Sports Brands </strong>using Spring Boot and Netflix Eureka Server in detail.</p><h3>Why there is a need for Spring Boot?</h3><p>Spring Boot enables building production-ready applications quickly and provides non-functional features:</p><ul><li>Embedded servers which are easy to deploy with the containers</li><li>It helps in monitoring the multiples components</li><li>It helps in configuring the components externally</li></ul><p>So, let us see what are the challenges with Microservices Architecture</p><h3>Challenges With Microservice Architectures</h3><p>While developing a number of smaller microservices might look easy, but there are number of inherent complexities that are associated with microservices architectures. Let’s look at some of the challenges:</p><ul><li><strong>Automating the Components</strong>: It becomes difficult to automate everything because there are a number of smaller components instead of a monolith, i.e. Builds, Deployment, Monitoring, etc.</li><li><strong>Perceptibility</strong>: There are¬†number of small components to deploy and maintain which sometimes becomes difficult to monitor and identify problems. It requires great perceptibility around all the components.</li><li><strong>Configuration Management</strong>: There is a great need to maintain the configurations for the components across the various environments.</li><li><strong>Debugging</strong>: It becomes difficult to probe each and every service for an error. Centralized Logging and Dashboards are essential to make it easy to debug problems.</li><li><strong>Consistency</strong>: You cannot have a wide range of tools solving the same problem. While it is important to foster innovation, it is also important to have some decentralized governance around the languages, platforms, technology and tools used for implementing/deploying/monitoring microservices.</li></ul><h3>Spring Boot Microservices: Building a Top Sports Brands Architecture with Spring Boot</h3><p>In this spring boot microservices example, we will be creating Top Sports Brands application which will be having 3 services:-</p><ol><li><strong>Eureka Service -</strong> This Service will register every microservice and then the client microservice will look up the Eureka server to get a dependent microservice to get the job done. This Eureka Server is owned by Netflix and in this, Spring Cloud offers a declarative way to register and invoke services by Java annotation.</li><li><strong>Item Catalog Service -</strong>This service will generate the list of Sports brands which are popular in the market.</li><li><strong>Edge Service -</strong>It is similar to the standalone Item service created in Bootiful Development with Spring Boot and Angular. However, it will have fallback capabilities which prevent the client from receiving an HTTP error when the service is not available</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQG5Ga5jMEeCuV3-G5brHg.png" /></figure><p>Let us see which of the following tools required to create this spring boot microservices example application.</p><h3>Tools Required</h3><ul><li>Java 8</li><li>Eclipse IDE Oxygen</li><li>Spring Tool</li></ul><p>If you facing any difficulty in installing and running the above tools, please refer to this <strong>blog</strong>.</p><h3>Spring Boot Microservices: Creating a Eureka Service</h3><p>To begin with, create a EurekaServer Spring Starter Project in Eclipse IDE. Click on <strong>Spring Starter Project </strong>and click on <strong>Next.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*O2SWVAzCe7V5W-LDoFJWVw.png" /></figure><p>Name your Spring Starter Project as <strong>EurekaServer </strong>and other Information will be filled <strong>automatically.</strong></p><p><strong>Note:- </strong>Make sure your Internet is connected otherwise it will show an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*q9vIJNGYft-yziY5sy9LSw.png" /></figure><p>Now, select <strong>Eureka Server </strong>as a dependency and click on <strong>Finish.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*AlROwFk3aNTibEcvXSkQhQ.png" /></figure><p>Now, modify EurekaServer/src/main/resources/application.properties file to add a port number and disable registration.</p><p>server.port=8761<br>eureka.client.register-with-eureka=false</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*chmyeAifE93-Vb8l5f7PgQ.png" /></figure><p>Open EurekaServer/src/main/java/com/example/EurekaServiceApplication.java and add @EnableEurekaServer above @SpringBootApplication.</p><pre>import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;</pre><pre>@EnableEurekaServer<br>@SpringBootApplication</pre><p>This annotation will configure a registry that will allow other applications to communicate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*CpaAFoRrUWlLxvlw3kS01Q.png" /></figure><p>To start the Application: Right Click on the <strong>Project</strong>¬&gt;<strong>Run As</strong>¬&gt; Click on “<strong>Spring Boot App</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4UEUCuDdrjePivIWJGuYg.png" /></figure><pre>After it starts, you should be able to open <a href="http://localhost:8761/">http://localhost:8761</a> and see there are no services available.</pre><p>Now open http://localhost:8761. Here Spring Eureka Server will open and will show no service will be running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*llz7jFNxtQzzcSZRrxtamg.jpeg" /></figure><h3>Spring Boot Microservices: Creating an Item Catalog Service</h3><p>Again create a new project. Use Item-catalog-service for the artifact name and click on <strong>Next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*Om8EpXMKz0334Zq5-xAMpw.png" /></figure><p>Add the following dependencies:</p><ul><li><strong>Actuator</strong>: features to help you monitor and manage your application</li><li><strong>Eureka Discovery</strong>: for service registration</li><li><strong>JPA</strong>: to save/retrieve data</li><li><strong>H2</strong>: an in-memory database</li><li><strong>Rest Repositories</strong>: to expose JPA repositories as REST endpoints</li><li><strong>Web</strong>: Spring MVC and embedded Tomcat</li><li><strong>DevTools</strong>: to auto-reload the application when files change</li><li><strong>Lombok</strong>: to reduce boilerplate code</li></ul><p>Click on <strong>Finish.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*qgI0w1LEI4Ky1wxSGGd9iQ.png" /></figure><p>Now, create an Item entity, toItemCatalogServiceApplication.java. The code below assumes you’re putting all classes in the same file.</p><pre>@Data<br>@AllArgsConstructor<br>@NoArgsConstructor<br>@ToString<br>@Entity<br>class Item {<br><br>    public Item(String name) {<br>        this.name = name;<br>    }<br><br>    @Id<br>    @GeneratedValue<br>    private Long id;<br><br>    private String name;<br>}<br><br>@RepositoryRestResource<br>interface ItemRepository extends JpaRepository&lt;Item, Long&gt; {}<br><br>@Component<br>class ItemInitializer implements CommandLineRunner {<br><br>    private final ItemRepository ItemRepository;<br><br>    ItemInitializer(ItemRepository itemRepository) {<br>        this.itemRepository = itemRepository;<br>    }<br><br>    @Override<br>    public void run(String... args) throws Exception {<br>        Stream.of(&quot;&quot;Lining&quot;, &quot;PUMA&quot;, &quot;Bad Boy&quot;, &quot;Air Jordan&quot;, &quot;Nike&quot;, &quot;Adidas&quot;, &quot;Reebok&quot;)<br>                .forEach(item -&gt; itemRepository.save(new Item(item)));<br><br>        itemRepository.findAll().forEach(System.out::println);<br>    }<br>}</pre><p>If you’re using an editor that doesn’t auto-import classes, here’s the list of imports needed at the top of ItemCatalogServiceApplication.java.</p><pre>import lombok.AllArgsConstructor;<br>import lombok.Data;<br>import lombok.NoArgsConstructor;<br>import lombok.ToString;<br>import org.springframework.boot.CommandLineRunner;<br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br>import org.springframework.cloud.client.discovery.EnableDiscoveryClient;<br>import org.springframework.data.jpa.repository.JpaRepository;<br>import org.springframework.data.rest.core.annotation.RepositoryRestResource;<br>import org.springframework.stereotype.Component;<br><br>import javax.persistence.Entity;<br>import javax.persistence.GeneratedValue;<br>import javax.persistence.Id;<br>import java.util.stream.Stream;</pre><p>Add an application name in item-catalog-service/src/main/resources/application.properties file to display in the Eureka service, and set the port to 8088.</p><p>server.port=8088</p><p>spring.application.name=item-catalog-service</p><p><strong>Now, Create the Cloud Properties file</strong></p><p>Click on <strong>File &gt; New &gt; Other &gt; File </strong>and add the below code in this file and save it.</p><pre>eureka.instance.hostname=${vcap.application.uris[0]:localhost}<br>eureka.instance.nonSecurePort=80<br>eureka.instance.metadataMap.instanceId=${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}<br>eureka.instance.leaseRenewalIntervalInSeconds = 5<br><br>eureka.client.region = default<br>eureka.client.registryFetchIntervalSeconds = 5<br>eureka.client.serviceUrl.defaultZone=${vcap.services.pwa-eureka-service.credentials.uri}/eureka/</pre><p>Now, to start the Application:</p><p>Right Click on Project &gt; <strong>Run As </strong>&gt; Click on ’<strong>Spring Boot App’</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8BWFkfQf9TtBIfO5tuYl5g.png" /></figure><p>Note: In case of error try this step: Right Click on the <strong>Project </strong>&gt; <strong>Run As </strong>&gt; Click on “<strong>Maven Build”</strong></p><p>Now open http://localhost:8761. Here you will see Item Catalog service will be running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*qlDX23FnqAKdJVmFgRZk7w.png" /></figure><p>You will see the list of items from the catalog service.</p><p>Open <a href="http://localhost:8088/items">http://localhost:8088/items</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*FXqqfqkgROzIIZ2mHbZfxw.jpeg" /></figure><p>Now let us move forward and create the Edge Service.</p><p><strong>Spring Boot Microservices: Creating an Edge Service</strong></p><p>It is similar to the standalone Item service created in <strong>Bootiful Development with Spring Boot and Angular</strong>. However, it will have fallback capabilities which prevent the client from receiving an HTTP error when the service is not available.</p><p>Again create a new project. Use edge-service for the artifact name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*64Sk5XYvoHNlvF4Q3fl8qg.jpeg" /></figure><ul><li><strong>Eureka Discovery</strong>: for service registration</li><li><strong>Feign</strong>: a declarative web service client</li><li><strong>Zuul</strong>: provides intelligent routing</li><li><strong>Rest Repositories</strong>: to expose JPA repositories as REST endpoints</li><li><strong>Web</strong>: Spring MVC and embedded Tomcat</li><li><strong>Hystrix</strong>: a circuit breaker to stop cascading failure and enable resilience</li><li><strong>Lombok</strong>: to reduce boilerplate code</li></ul><p>Click on <strong>Finish.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*wytBFdFKBSo1xmWZT3Wmqw.jpeg" /></figure><p>Since the item-catalog-service is running on port 8088, you’ll need to configure this application to run on a different port. Modify edge-service/src/main/resources/application.properties¬†to set the port to 8089 and set an application name.</p><pre>server.port=8089<br>spring.application.name=edge-service</pre><p><strong>Now, Create the Cloud Properties file</strong></p><p>Click on <strong>File &gt; New &gt; Other &gt; File </strong>and add below code in this file and save it.</p><pre>eureka.instance.hostname=${vcap.application.uris[0]:localhost}<br>eureka.instance.nonSecurePort=80<br>eureka.instance.metadataMap.instanceId=${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}<br>eureka.instance.leaseRenewalIntervalInSeconds = 5<br><br>eureka.client.region = default<br>eureka.client.registryFetchIntervalSeconds = 5<br>eureka.client.serviceUrl.defaultZone=${vcap.services.pwa-eureka-service.credentials.uri}/eureka/</pre><p>To enable Feign, Hystrix, and registration with the Eureka server, add the appropriate annotations toEdgeServiceApplication.java:</p><pre>package com.example.edgeservice;<br><br>import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;<br>import lombok.Data;<br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br>import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;<br>import org.springframework.cloud.client.discovery.EnableDiscoveryClient;<br>import org.springframework.cloud.netflix.feign.EnableFeignClients;<br>import org.springframework.cloud.netflix.feign.FeignClient;<br>import org.springframework.cloud.netflix.zuul.EnableZuulProxy;<br>import org.springframework.hateoas.Resources;<br>import org.springframework.web.bind.annotation.*;<br><br>import java.util.ArrayList;<br>import java.util.Collection;<br>import java.util.stream.Collectors;<br><br>@EnableFeignClients<br>@EnableCircuitBreaker<br>@EnableDiscoveryClient<br>@EnableZuulProxy<br>@SpringBootApplication<br>public class EdgeServiceApplication {<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(EdgeServiceApplication.class, args);<br>    }<br>}</pre><p>Create a Item DTO (Data Transfer Object) in this same file. Lombok&#39;s<a href="https://projectlombok.org/features/Data.html">@Data</a> will generate a toString() methods, getters, setters, and appropriate constructors.</p><pre>@Data<br>class Item {<br>    private String name;<br>}</pre><p>Create a ItemClient interface that uses Feign to communicate to the Item-catalog-service.</p><pre>public class EdgeServiceApplication {<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(EdgeServiceApplication.class, args);<br>    }<br>}<br><br>@Data<br>class Item {<br>    private String name;<br>}<br><br>       public String getName() {<br>             return name; <br>}<br> <br>public void setName(String name) { <br>                      this.name = name;<br>          }<br>@FeignClient(&quot;item-catalog-service&quot;)<br>interface ItemClient {<br><br>    @GetMapping(&quot;/items&quot;)<br>    Resources&lt;Item&gt; readItems();<br>}</pre><p>Create a RestController below the ItemClient that will filter out less-than-top brands and shows a /top-brandsendpoint.</p><pre>@RestController<br>class GoodItemApiAdapterRestController {<br><br>    private final ItemClient itemClient;<br><br>    public GoodItemApiAdapterRestController(ItemClient ItemClient) {<br>        this.itemClient = itemClient;<br>    }<br><br>    @GetMapping(&quot;/top-brands&quot;)<br>    public Collection&lt;Item&gt; goodItems() {<br>        return itemClient.readItems()<br>                .getContent()<br>                .stream()<br>                .filter(this::isGreat)<br>                .collect(Collectors.toList());<br>    }<br><br>    private boolean isGreat(Item item) {<br>        return !item.getName().equals(&quot;Nike&quot;) &amp;&amp;<br>                !item.getName().equals(&quot;Adidas&quot;) &amp;&amp;<br>                !item.getName().equals(&quot;Reebok&quot;);<br>    }<br>}</pre><p>Start the edge-service application with Maven or your IDE and verify it registers successfully with the Eureka server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*oC1gMJnZBBpoySo5jU2flg.png" /></figure><p>Now invoke localhost:8089/top-brands, you will see the list of top brands from the catalog service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*Zzc_xGg_k5sB30IpuF4BOQ.jpeg" /></figure><p><strong>Note: </strong>If you shut down the item-catalog-service application, you’ll get a 500 internal server error.</p><pre>$ http localhost:8089/top-brands<br>HTTP/1.1 500<br>Connection: close<br>Content-Type: application/json;charset=UTF-8<br>Date: Fri, 16 Mar 2018 12:51:22 GMT<br>Transfer-Encoding: chunked<br>X-Application-Context: edge-service:8089</pre><pre>{<br>    &quot;error&quot;: &quot;Internal Server Error&quot;,<br>    &quot;exception&quot;: &quot;feign.RetryableException&quot;,<br>    &quot;message&quot;: &quot;connect timed out executing GET http://item-catalog-service/items&quot;,<br>    &quot;path&quot;: &quot;/top-brands&quot;,<br>    &quot;status&quot;: 500,<br>    &quot;timestamp&quot;: 1328088897672<br>}</pre><p>To fix this, you can use Hystrix to create a fallback method and tell the goodItems() method to use it.</p><pre>public Collection&lt;Item&gt; fallback() {<br>    return new ArrayList&lt;&gt;();<br>}<br><br>@HystrixCommand(fallbackMethod = &quot;fallback&quot;)<br>@GetMapping(&quot;/top-brands&quot;)<br>public Collection&lt;Item&gt; goodItems() {<br>    return ‚Ä¶ <br>}</pre><p>Restart the edge-service and you should see an empty list returned.</p><pre>$ http localhost:8089/top-brands<br>HTTP/1.1 200<br>Content-Type: application/json;charset=UTF-8<br>Date: Fri, 16 Mar 2018 12:59:02 GMT<br>Transfer-Encoding: chunked<br>X-Application-Context: edge-service:8089</pre><pre>[]</pre><p>Start the item-catalog-service again and this list should eventually return the full list of top brands names.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3da3769c7d41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building and consuming GraphQL API in ASP.NET Core 3.1]]></title>
            <link>https://medium.com/@JayArOnde/building-and-consuming-graphql-api-in-asp-net-core-3-1-a636e4a96ce6?source=rss-185fe2f126f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/a636e4a96ce6</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[dotnet-core-3]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Jay Ar Onde]]></dc:creator>
            <pubDate>Sat, 05 Mar 2022 17:27:33 GMT</pubDate>
            <atom:updated>2022-03-05T17:27:33.994Z</atom:updated>
            <content:encoded><![CDATA[<p>It was in the year 2012 that Facebook decided to rebuild their apps to improve performance and efficiency. It was a time when Facebook’s mobile strategy wasn’t working because of high network usage. Optimization strategies using caching might have improved the performance, but since the app was too complex, it was thought that the data fetching strategy itself should be changed. Here’s where GraphQL came in, and today it has become extremely popular among the development community worldwide. GraphQL, developed by Facebook in 2012 and open-sourced 2015, is now maintained by the GraphQL Foundation.</p><p>GraphQL is a platform-agnostic, language-neutral query language that has been around for quite some time now and can be used to execute queries and fetch data. Similar to REST, GraphQL is a specification that provides an elegant and flexible way to query your data. This article discusses the features and benefits of GraphQL and then illustrates how one can work with GraphQL in ASP.NET Core 3.1.</p><h3>Prerequisites</h3><p>To work with the code examples illustrated in this article, you should have Visual Studio 2019 installed on your computer. If you don’t have a copy of it yet, you can grab one from <a href="https://visualstudio.microsoft.com/downloads/">here</a>. If you don’t have .NET Core installed in your system, you can download a copy from <a href="https://dotnet.microsoft.com/download/archives">here</a>.</p><h3>Why do you need GraphQL?</h3><p>GraphQL is a JSON-like query language for APIs as well as a server-side runtime for executing your queries. Unlike REST where the request and response are defined by the API, in GraphQL, the client has complete control on what data the API should return. You can integrate GraphQL with ASP.NET, ASP.NET Core, Java, etc.</p><p>If you are working on an application that leverages RESTful architecture, the endpoints might grow over time and maintaining them might become a nightmare. On the contrary, with GraphQL, you just need one endpoint api/graphql, and that’s all. This is another significant difference between REST and GraphQL.</p><p>In using GraphQL you need fewer roundtrips to the server, i.e., you need fewer back-and-forth calls to the server to get all the data you need. With REST, you will have several endpoints such as api/students, api/teachers, api/batches, etc.</p><p>Unlike REST, when using GraphQL, you will never have too little or too much data — you can define your queries and all data you need.</p><p>When using GraphQL, you need not worry about versioning. The fact is that GraphQL doesn’t need versioning and as long as you don’t delete fields from the types, the clients or consumers of the API wouldn’t break.</p><p>When using GraphQL, you would typically need fewer requests and less bandwidth. You need just a single call to the API to get the data you need. Moreover, you can specify the fields you need when making a request. Instead of returning all fields for a type, you can retrieve only what you need hence saving on bandwidth and resource usage.</p><p>Similar to Swagger that generates documentation for the REST endpoints, GraphQL can also generate documentation for the GraphQL endpoint.</p><p>Albeit all the advantages GraphQL has to offer, there are a few downsides as well. You can read about those by clicking the <a href="https://www.basdecort.com/graphql-for-dotnet/">link</a>.</p><h3>GraphQL vs REST</h3><p>Here’s a quick look at how GraphQL compares with REST:</p><ol><li>Unlike REST where you might need to have several endpoints to get you the data you need, GraphQL exposes only a single endpoint.</li><li>REST works on Http only while GraphQL doesn’t need Http to work.</li><li>Unlike REST where you can use any Http verb, GraphQL recommends using only the Http POST verb</li><li>Unlike REST where the request and response are defined by the API, the clients or the consumers of GraphQL can define what data they need. While the size of the resource is determined by the server when working with REST, in GraphQL, the API defines the available resources, and the client requests only what it needs.</li><li>Both REST and GraphQL are platform and language agnostic, and both are adept at returning JSON.</li></ol><h3>Building Blocks of GraphQL</h3><p>The main building blocks of GraphQL include schemas and types.</p><h3>Schema</h3><p>There is one, and only one endpoint in GraphQL. This endpoint exposes a schema that is used to let the API consumer know the functionality available for the clients to consume, i.e., what data they can expect and the actions they can perform. A Schema in GraphQL is represented by a class that extends the Schema class pertaining to the GraphQL.Types namespace.</p><p>A schema contains a Query, Mutation, and a Subscription.</p><ol><li>Query — Queries enable you to consume data efficiently. The consumer or the client can mention the field or fields it needs in lieu of getting data for all fields from a particular type. Note that the client can only consume the fields that have been exposed by the API.</li><li>Mutation — In GraphQL mutations are used to send data to the server, i.e., you can take advantage of mutations to add, edit, or delete data. The client can only take advantage of the mutations that have been exposed by the schema to modify the data. It should be noted here that if there are no mutations in a GraphQL schema, the client cannot manipulate the data in the API.</li><li>Subscription — Subscriptions allow a server to send data to its clients, hence notifying them when events occur. Subscriptions provide support for event-driven architectures and for real-time notifications they take advantage of WebSockets.</li></ol><h3>GraphQL Object Types</h3><p>The most fundamental components of a GraphQL schema are object types, which in turn are used to represent the type of object you can retrieve from your API. Object Types in GraphQL are represented by the GraphQL.Types.ObjectGraphType class and contain Fields and Methods. While the former is a property in the class, the latter is used to modify field values when needed based on a client query.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a636e4a96ce6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices Using ASP.NET Core]]></title>
            <link>https://medium.com/@JayArOnde/microservices-using-asp-net-core-dd14396ba9a4?source=rss-185fe2f126f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd14396ba9a4</guid>
            <category><![CDATA[aspnet-development]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <dc:creator><![CDATA[Jay Ar Onde]]></dc:creator>
            <pubDate>Sat, 05 Mar 2022 16:44:08 GMT</pubDate>
            <atom:updated>2022-03-05T16:44:08.174Z</atom:updated>
            <content:encoded><![CDATA[<h4>Microservices</h4><p>The term microservices portrays a software development style that has grown from contemporary trends to set up practices that are meant to increase the speed and efficiency of developing and managing software solutions at scale. Microservices is more about applying a certain number of principles and architectural patterns as architecture. Each microservice lives independently, but on the other hand, also all rely on each other. All microservices in a project get deployed in production at their own pace, on-premise on the cloud, independently, living side by side.</p><p>In this article, we will learn the concept of Microservices, their architecture, and how to create microservices in .NET and C#. You will also learn steps to¬†build, deploy, and test microservices in .NET using a docker container.</p><h4>Microservices Architecture</h4><p>The following picture from Microsoft Docs shows the microservices architecture style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*l4lDYWQsGGgHErgmAlDE8g.png" /></figure><p>There are various components in a microservices architecture apart from microservices themselves.</p><p><strong>Management</strong>. Maintains the nodes for the service.</p><p><strong>Identity Provider</strong>. Manages the identity information and provides authentication services within a distributed network.</p><p><strong>Service Discovery</strong>. Keeps track of services and service addresses and endpoints.</p><p><strong>API Gateway</strong>. Serves as client‚Äôs entry point. Single point of contact from the client which in turn returns responses from underlying microservices and sometimes an aggregated response from multiple underlying microservices.</p><p><strong>CDN</strong>. A content delivery network to serve static resources for e.g. pages and web content in a distributed network</p><p><strong>Static Content</strong>¬†The static resources like pages and web content</p><p>Microservices are deployed independently with their own database per service so the underlying microservices look as shown in the following picture.</p><h3>Monolithic vs Microservices Architecture</h3><p>Monolithic applications are more of a single complete package having all the related needed components and services encapsulated in one package.</p><p>Following is the diagrammatic representation of monolithic architecture being package completely or being service based.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*nT-TT1n1ITyGWERFrRyx-A.png" /></figure><p>Microservice is an approach to create small services each running in their own space and can communicate via messaging. These are independent services directly calling their own database.</p><p>Following is the diagrammatic representation of microservices architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*54ytHhzK9b09CwKayMfAkw.png" /></figure><p>In monolithic architecture, the database remains the same for all the functionalities even if an approach of service-oriented architecture is followed, whereas in microservices each service will have its own database.</p><h3>Docker Containers and Docker installation</h3><p>Containers like Dockers and others slice the operating system resources, for e.g. the network stack, processes namespace, file system hierarchy and the storage stack. Dockers are more like virtualizing the operating system. Learn more about dockers <a href="https://www.docker.com/resources/what-container">here</a>. Open <a href="https://docs.docker.com/docker-for-windows/install/">this</a> URL and click on Download from Docker hub. Once downloaded, login to the Docker and follow instructions to install Docker for Windows.</p><h3>Microservice using ASP.NET Core</h3><p>This section will demonstrate how to create a Product microservice using ASP.NET Core step by step with the help of pictures. The service would be built using ASP.NET Core 2.1 and Visual Studio 2017. Asp.NET Core comes integrated with VS 2017. This service will have its own DBcontext and database with the isolated repository so that the service could be deployed independently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*JLxpiQJLTZsgrYzzepZLyw.png" /></figure><h3>Creating an ASP.NET Core Application Solution</h3><p>Open the Visual Studio and add a new project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*2z7H7wCvDF9ZrYNqyC7m5Q.png" /></figure><p>Choose the application as ASP.NET Core Web Application and give it a meaningful name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*8ZK51B1gNsk5SutgyDfpJg.png" /></figure><p>Next, choose API as the type of the project and make sure that ‚ÄúEnable Docker Support‚Äù option is selected with OS type as Linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*MJh8VhIN0ScGg6--gSxeIg.jpeg" /></figure><p>The solution will look as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*L16w-8FyjUDRZae-i4ib3Q.png" /></figure><h3>Adding Models</h3><p>Add a new folder named “Model” to the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*u3UmzpcXn-KJzOHdV1E5ng.png" /></figure><p>In the Models folder, add a class named Product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*bQUB7UC33kWVWuG1vF16eA.png" /></figure><p>Add a few properties like Id, Name, Description, Price to the product class. The product should also be of some kind and for that, a category model is defined and a CategoryId property is added to the product model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*6sInPZLrn5wldQ_wEplWBw.png" /></figure><p>Similarly, add Category model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*aKXt3551NXp2Mg8ffajwng.png" /></figure><h3>Enabling EF Core</h3><p>Though .NET Core API project has inbuilt support for EF Core and all the related dependencies are downloaded at the time of project creation and compilation that could be found under SDK section in the project as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*b8LbmIWUvaNkA5bCraNcMg.png" /></figure><p>Microsoft.EntityFrameworkCore.SqlServer (2.1.1) should be the package inside the downloaded SDK’s. If it is not present, it could be explicitly added to the project via Nuget Packages.</p><h3>Adding EF Core DbContext</h3><p>A database context is needed so that the models could interact with the database.</p><p>Add a new folder named DBContexts to the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*ndcZrrSvt4nmSOGwLsMJIQ.png" /></figure><p>Add a new class named ProductContext which includes the DbSet properties for Products and Categories. OnModelCreating is a method via which the master data could be seeded to the database. So, add the OnModelCreating method and add some sample categories that will be added to the database initially into the category table when the database is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*mvL3smBVKMmW7zROspXBOA.png" /></figure><p><strong>ProductContext code</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/433b98c995571f93ba292da91be62ab8/href">https://medium.com/media/433b98c995571f93ba292da91be62ab8/href</a></iframe><p>Add a connection string in the appsettings.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*yzDhZIkDcBcAQJF-DUPKqw.png" /></figure><p>Open the Startup.cs file to add the SQL server db provider for EF Core. Add the code services.AddDbContext&lt;ProductContext&gt;(o =&gt; o.UseSqlServer(Configuration.GetConnectionString(“ProductDB”))); under ConfigureServices method. Note that in the GetConnectionString method the name of the key of the connection string is passed that was added in appsettings file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*4NtGp-gEYSbc4vXj-5wzOA.jpeg" /></figure><h3>Adding Repository</h3><p>Repository works as a micro component of microservice that encapsulates the data access layer and helps in data persistence and testability as well.</p><p>Add a new folder named Repository in the project and add an Interface name IProductRepository in that folder. Add the methods in the interface that performs CRUD operations for Product microservice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*2EIc3d_qtf1ubmzo6mxAPA.png" /></figure><p>Add a new concrete class named ProductRepository in the same Repository folder that implements IProductRepository. All these methods need:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*gA4pwbJ5oMkQHQt18vSPuA.png" /></figure><p>Add the implementation for the methods via accessing context methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80917e880950a90f276646adcb86cbb5/href">https://medium.com/media/80917e880950a90f276646adcb86cbb5/href</a></iframe><p>Open the Startup class in the project and add the code as services.AddTransient&lt;IProductRepository, ProductRepository&gt;(); inside ConfigureServices method so that the repository’s dependency is resolved at a run time when needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*YG-E2kl2YGxXSIpasrsVQQ.jpeg" /></figure><h3>Adding Controller</h3><p>The microservice should have an endpoint for which a controller is needed which exposes the HTTP methods to the client as endpoints of the service methods.</p><p>Right click on the Controllers folder and add a new Controller as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*YZO_r9TuLqk-AC0aqZMz4Q.png" /></figure><p>Select the option ‚ÄúAPI Controller with read/write actions‚Äù to add the controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*Zu0TmcoFpspOVz18FLx7_Q.png" /></figure><p>Give the name of the controller as ProductController.</p><p>A ProductController class will be added in the Controllers folder with default read/write actions that will be replaced later with product read/write actions and HTTP methods are created acting as an endpoint of the service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*yOi8Xfs5EzvdrYVH_qGg1A.png" /></figure><p>ValuesController can be deleted as it is not needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*tydCNVHkc1kAsAyf2NY-wQ.png" /></figure><p>Add implementation to the methods by calling the repository methods as shown below. The basic implementation is shown here for the sake of understanding the concept. The methods could be attribute routed and could be decorated with more annotations as per need.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b381ea10828e5e231189605c841f31e9/href">https://medium.com/media/b381ea10828e5e231189605c841f31e9/href</a></iframe><h3>Entity Framework Core Migrations</h3><p>Migrations allow us to provide code to change the database from one version to another.</p><p>Open Package Manager Console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*vvYQP8n4FpFWmXIgJUU0jQ.png" /></figure><p>To enable the migration, type the command, Add-Migration and give that a meaningful name for e.g. InitialCreate and press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*PJaaAUKd2pI2-xKdZc7OKA.png" /></figure><p>Once the command is executed, if we look at our solution now, we see there’s a new Migrations folder. And it contains two files. One, a snapshot of our current context model. Feel free to check the files. The files are very much self-explanatory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*k68LoIUcjcD2pzgyQvm_jg.png" /></figure><p>To ensure that migrations are applied to the database there’s another command for that. It’s called the update-database If executed, the migrations will be applied to the current database.</p><p>Check the SQL Server Management Studio to verify if the database got created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*Ehs2FhNZpEy26DZDH_i9nw.png" /></figure><p>When data of the Categories table is viewed the default master data of three categories is shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*wgSTI-RLPagG0SbdvhP-EA.png" /></figure><h3>Run the Product Microservice</h3><p>The service could be run via IIS Express i.e. Visual Studio default or via Docker container as well.</p><h3>Via IIS Express</h3><p>Choose IIS Express in the Visual Studio as shown below and press F5 or click that IIS Express button itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*ISwYeKfuLsoulC-H8mVEzw.jpeg" /></figure><p>The application will be up once the browser page is launched. Since it has nothing to show, it will be blank, but the service could be tested via any API testing client. Here Postman is used to testing the service endpoints. Keep it opened and application running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*HbC2CWfUslB-SWexVRdTpQ.png" /></figure><p>Install Postman if it is not on the machine and launch it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*qCMdOFuC1zwO_fxFX3trbQ.png" /></figure><p><strong>POST</strong></p><p>To test the POST method; i.e. create a new resource, select the method as POST in postman and provide the endpoint, i.e. <a href="https://localhost:44312/api/product">https://localhost:44312/api/product</a> and in the Body section, add a JSON similar to having properties of Product model as shown below and click on Send.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*kYlhj8qAv-EfTVJhbHkk-Q.png" /></figure><p>The response is returned with the Id of the product as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*KVqpAspvJQ7U9WrHGQoxPw.png" /></figure><p>The “Post” method of the controller is responsible to create a resource in the database and send the response.</p><p>The line return CreatedAtAction(nameof(Get), new { id=product.Id }, product); returns the location of the created resource that could be checked in Location attribute in the response under Headers tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*ZxM2j_vmbnl4COqkGX0rcg.png" /></figure><p>Perform a select query on the product table and an added row is shown for the newly created product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*y9uDUZZ9Q2w9xEc6qLl_3w.png" /></figure><p>Create one more product in a similar way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*ymgYM97H4ywH-5G1Bn18uQ.png" /></figure><p><strong>GET</strong></p><p>Perform a GET request now with the same address and two records are shown as a JSON result response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*37UUmyJpfN0l9JxItGmj6g.png" /></figure><p><strong>DELETE</strong></p><p>Perform the delete request by selecting DELETE as the verb and appending id as 1 (if the product with id 1 needs to be deleted) and press Send.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*RkaP4ckPcRUNen_FiL0ixw.png" /></figure><p><strong>PUT</strong></p><p>PUT verb is responsible for updating the resource. Select PUT verb, provide the API address and in the Body section, provide details of which product needs to be updated in JSON format. For example, update the product with Id 2 and update its name, description, and price from Samsung to iPhone specific. Press Send.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*vxL4N233mWp3TiHeXUibNg.png" /></figure><p>Check the database to see the updated product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*v4BjbA-N4hq03Sc3Z7HSxA.png" /></figure><h3>Via Docker Containers</h3><p>Running the service could be done via docker commands to be run in docker command prompt and using visual studio as well. Since we added the docker support, it is easy to run the service in docker container using visual studio.</p><p>Add container orchestrator support in the solution as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*A5TUOqI6KOtfbkoC5j6opA.jpeg" /></figure><p>This will ask for the orchestrator. Select Docker Compose and press OK.</p><p>Once added to the solution, the solution will look like shown below having docker-compose with dockerignore and docker-compose.yml and its override file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*S05VRYwz-zhSLWDtZXtNug.jpeg" /></figure><p>As soon as the solution is saved, it builds the project under the container and creates a docker image. All the commands execution can be seen in the output window when the solution is saved.</p><p>Open the command prompt in admin mode and navigate to the same folder where the project files are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*V7oI-IK2BW6tTecyXRHchw.png" /></figure><p>Run the command docker images to see all the created images. We see the ProductMicroserviceimage the latest one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*Hd5c5HsqvccQQWL32FquJQ.png" /></figure><p>Now run the application with Docker as an option as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*DRG-L_RWpU0V8n176afuSw.png" /></figure><p>Now, run the command docker ps to see the running containers. It shows the container is running on 32773:80 port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*oux-21aNlxi-hcRD5MoLPg.jpeg" /></figure><p>Since the container is in running state, it is good to test the service now running under the container. To test the service, replace “values” with “product” in the address as shown below. Ideally, it should get the product details. But it gives exception as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*8YweW1RF1b7lMJn38QC17w.png" /></figure><p>Running the same thing under IIS Express works fine i.e. on port 44312. Replace ‚Äúvalues‚Äù with the product to get the product details,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*f0TSSJECufoOcrppCyjiVA.jpeg" /></figure><p>Since in IIS Express application runs fine and not in docker container, the error clearly shows that something is wrong with the SQL server that it does not understand our docker container or it is not running under docker container. In this scenario, the docker container is running as a separate machine inside the host computer. So, to connect to the SQL database in the host machine, remote connections to SQL needs to be enabled. We can fix this.</p><p>Open the SQL Server Configuration Manager. Now select Protocols for MSSQLSERVER and get the IPAll port number under TCP/IP section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*UMVJoXYmvRPePDgdDCkY0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*xNrx5Y1mcz1lxpK1JEnzFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*oelqb9uTU5HeCixzK8yxPA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*0TTna9IOtCMu0Kc3GxYjhg.png" /></figure><p>The connection string mentioned in the JSON file points to the data source as local which the docker container does not understand. It needs proper IP addresses with port and SQL authentication. So, provide the relevant details i.e. Data Source as Ip address, port number and SQL authentication details as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*sMq9DThW95iGjYIlxHyEyw.png" /></figure><p>Now again run the application with Docker as an option like done earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*WeudPFZhTX_RYFB34mjg6Q.jpeg" /></figure><p>This time the response is received.</p><p>Test the same in the Postman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*lffUeT65d_goZXPeQ04Kxg.png" /></figure><p>Test again with IIS Express URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*iG2v94oyIh_chfTJtBE_Dg.jpeg" /></figure><p>This proves that the microservice is running on two endpoints and on two operating systems independently locally deployed.</p><h3>Conclusion</h3><p>A microservice is a service built around a specific business capability, which can be independently deployed which is called bounded context. This article on microservices focused on what microservices are and their advantages over monolithic services architecture. The article in detail described to develop a microservice using ASP.NET Core and run it via IIS and Docker container. Likewise, the service can have multiple images and could be run on multiple containers at the same point in time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd14396ba9a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>