If you followed along the series of exercises I’ve been sharing in this website, our previous exercise was intended to create a Console Application (with interesting complexities) to be used for CRUD operations on a Book Library shop.
If you missed it, please make sure to have a look here: C# Exercise – Book Library Console Application
In today’s exercise, we will extend this existing solution, with a new layer which will act as a RESTful API. It will be a .NET WebAPI project with the proper endpoints and the ability to reuse all the architecture that is already set on the solution.
If you didn’t practice on the previous exercise don’t worry, just grab the example I’ve coded in my Github HERE , it’s ready to use.
Requirements and Challenges in this exercise
- Extend an existing solution, without modifying anything from the architecture.
- Implement a RESTful API approach using a Controller with the proper Endpoints and reuse the existing BookService to get access to the CRUD operations.
- For the purpose of this exercise use sync methods on the controller
- Enhance the solution with Logging capabilities (Custom made, Serilog, etc. Your choice)
- Setting up a Docker image, so we deploy the App into a container, and run it there (Use default ports to browse the API inside the container)
- Push the enhanced solution into your Github profile. (GIT Basics here)
Optional Challenges
If you want to go even further making use of this existing exercise, I propose the following:
- Upgrade the Controller to run async methods. All implementation should be improved to handle async requests
- Implement MediatR with CQRS to handle the requests. Popular and modern approach with API development these days.
- Move the Console App as “Legacy” code, yet functional but clearly visible on the solution as an old and unused approach, close to decommission. BookService is also targeted as Legacy code, the new approach using handlers will replace the service with a modern approach.
- Implement basic validation with FluentValidation
The Solution
As usual, you can find my own implementation in my Github profile, as a way to compare your code and check my approach for the exercise. You can also use it to validate your code and get inspiration, if you get stuck at some point. But as a rule of thumb, always try to implement your own solution first, and get used to investigate problems before seeking for an existing approach to review. This is what will make a better developer out of you, a problem solver.
Repo: https://github.com/marcelomusza/LibraryExerciseAPIWithDocker
In addition to this, if you went even further with the optional challenges, I have a private repository for the proposed solution, accessible only by my Patreons. If you are interested in contributing with an active community of developers, and helping with the support of this project, please consider subscribing! We’ll love to have you onboard.
For more information about Patreon, click here.
The private Repo: https://github.com/marcelomusza/LibraryExerciseAPIWithDocker_Private
See you on the next Exercise, happy coding!