Store2008 Review - Overview of the .Net Monolithic Code
Store2018 - Refactor and Redesign
The course is part of this learning path
In this advanced course, we take a legacy monolithic .Net application and re-architect it to use a combination of cloud services to increase scalability, performance, and manageability.
This course will enable you to:
- Learn the principles and patterns associated with microservices
- Understand the principles and patterns associated with Restful APIs
- Learn important requirements to consider when migrating a monolithic application into a microservices architecture
- Master the benefits of using microservices and associated software patterns and tools to build microservice-based applications at speed and scale
- Understand tradeoffs between different architectural approaches
- Become comfortable with modern open source technologies such as Dotnet Core, Docker, Docker Compose, Linux, Terraform, Swagger, React
- Become familiar with Docker and Container orchestration runtimes to host and run containers, such as Docker Compose, Amazon ECS using Fargate, and Amazon EKS
- A basic understanding of software development
- A basic understanding of the software development life cycle
- A basic understanding of DevOps and CICD practices
- Familiarity with Dotnet and C#
- Familiarity with AWS
- Software Developers and Architects
- DevOps Practitioners interested in CI/CD implementation
- Anyone interested in understanding and adopting Microservices and Restful APIs within their own organization
- Anyone interested in modernizing an existing application
- Anyone interested in Docker, and Containers in general
- Anyone interested in container orchestration runtimes such as Kubernetes
- [Narrator] Welcome back. In the previous lecture we completed the process of containerizing our microservices architecture. In this lecture we'll move forward by introducing you to a new tool called Swagger. Swagger is an open source software tool that helps developers design, build, document and consume RESTful APIs. To give you an idea of what Swagger can accomplish, let's take a look at the online pet store example. This is hosted at petstore.swagger.io. So as you can see Swagger provides a user interface that documents the pet store API.
If we scroll down we can see each of the different request methods. We have a post to the /pet resource and if we expand on this, we can see how this particular request is expected to be used. Even better the Swagger UI gives us the ability to execute a test on the API within the interface. Clicking the try out button we can edit the body that is posted to the pet resource or we can simply execute it. Here we can see the response code was 200 and that the response body is an XML document. The Swagger interface even gives us a nice kill command which we can copy. And jumping into our terminal we can simply paste and execute. Again we can see that we've got an XML document returned. Okay from here let's talk about where we'll use this in our design.
So if you recall we have three service components. Each of these has been Web API enabled using the ASP .NET Core Web API framework and therefore each of these presents a RESTful API interface and it would be very useful to provide documentation on these APIs to our developers. So let's jump into Visual Studio and begin this process. So the first thing we need to do is we need to import the Swashbuckle implementation of the Swagger user interface. So here we can see the GitHub repository for the Swashbuckle AspNetCore library. So we'll take a copy of this. Jumping back into Visual Studio, for each of our services we'll go into dependencies and right click on NuGet, add packages and search for Swashbuckle.AspNetCore.
Okay so this is the one we want, version 3.0.0 and we'll add package. So again we'll repeat this for the inventory service. Dependencies, NuGet, right click, add packages. Search for Swashbuckle. Make sure it's 3.0.0, add package. And then finally for shopping service. Okay, so expanding our NuGet packages we can see that we've successfully added. And on shopping service, Swashbuckle.ASP.NET so that's great. Next for each of our service APIs, we need to update the Startup.cs file. First thing we need to do is import a Swashbuckle.AspNetCore.swagger datatype. Next under configure services under the .AddNVC method we'll call services.AddSwaggerGen, specifying a Lambda function. And here we'll call c.SwaggerDoc and the parameters will be V1, new info where the property's our title equals account service API and whereby the version is set to V1. Following on we need to update the configure method and enable the Swashbuckle middleware. Reduce over-calling app.UseSwagger, followed by calling app.
Use SwaggerUI for user interface and again we specify Lambda function. And this time we specify cw.Swagger Endpoint and we specify an endpoint which will be the URL that we can call. So in this case we'll call, we'll make it swagger/v1/swagger.json. And again we give it a title. We'll call it account service API version one. Okay so I think at this stage we should be good to go. So let's compile. Excellent, compilation has succeeded and now we'll ensure that the account service is set to start up and we'll start up this project. And then we'll navigate to this URL. Okay so the project's started up.
Let's now navigate to the Swagger URL and excellent. So we've got our Swagger definition file. Now if we navigate back to just /swagger, you'll see that we have got our documentation automatically generated for our account service API. And this is extremely useful because we can hand this over to our developers and the developers can immediately understand how our API is designed and how to use it. So in this case if we want to get a particular consumer by ID, we can try it out, we can specify the ID, in this case we'll specify ID five. We'll execute and here is the response so there's some JSON response code 200. Okay that completes this lecture. Go ahead and close it and we'll see you shortly in the next one.
About the Author
Jeremy is the DevOps Content Lead at Cloud Academy where he specializes in developing technical training documentation for DevOps.
He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 20+ years. In recent times, Jeremy has been focused on DevOps, Cloud, Security, and Machine Learning.
Jeremy holds professional certifications for both the AWS and GCP cloud platforms.