A .NET REST API using C# built to store UNIX commands
technologies used: C#, Docker, Kubernetes, Postman, xunit (unit tests), MongoDB
Features and concepts:
Dependency injection: The dependency inversion principle states that our controller should depend on an abstraction/interface that all other dependencies will implement. This feature will help in scalability as the controller here has no idea what dependencies it is working with. In the future, i can simply "inject" the dependency and do not need to change the implementation of controller.
Decoupling implementations from each other makes testing, upgrades easier.
DTOs (Data transferable objects): We need a contract between the clients and out API and DTOs are that contract. This is almost like type safety/checking where both the api and client must respect the contract. We do not want anything other than a string for command for example.
What makes this API RESTful: A REST api must support at minimum 4 calls: PUT: modify an existing entry POST: add a new entry GET: get an existing entry DELETE: delete an existing entry
Persistence of entities using MongoDB: MongoDB hosted on docker was used to store the unix commands.
Deployment to Docker: public docker pull command: docker pull deepan19/unixstore link to docker hub page: https://hub.docker.com/r/deepan19/unixstore
Why docker? advantages of docker: Deployment is challenging as the client's PC may not have the OS, environment, dependencies, .NET runtime, mongodb driver that are required for the api to run in production. Also we have a MongoDB database and its own dependencies that needs to run in production. A docker container contains everything our RESTapi needs to run in another PC Our RESTapi -> docker file -> build a docker image using docker engine -> push a docker container
Kubernetes: the kubernetes control plane schedules, load balances, selfheals, allocates pods (collection of containers) to nodes based on cpu, scales up containers: turns desired state into actual state
self heal capability of API container:
self-heal capability of MongoDB service:
- unit testing using xunit and postman unit testing is to make sure individual methods work in isolation without external dependencies. Can prevent expensive bug fixes later on as we scale.
testing all requests using postman:
TDD(test driven development) was used for testing: write a test before writing enough production code to make the failting test pass. write a failing test->write code to make it pass -> Refactor