Create CRUD api without writing code

I am obsessed with reusability of code. As a result of that, I am always refactoring code. What do you do when you find a piece of code that you think could be reused? Well, I publish it online on repositories like nuget. Think about it. It’s the next step after you have extracted the reusable code into a class.

I have published multiple projects to nuget and I feel happy about it because I have not only helped my teammates but also helped anyone in the word who otherwise would have had to re-write that functionality. It doesn’t matter how small the functionality is as long as it’s generic and reusable.

One such project I recently pushed to nuget is LiteDB.AutoApi. It works on top of LiteDB. LiteDb is Embedded NoSQL database for .NET. The purpose of this library is to reduce the amount code you write for creating a simple CRUD apis.

Let’s say you have a domain model and you want to create an api around it. Let’s call it Person model. API requirements are simple. It needs to persists data locally and provide these endpoints:

  • GET /people/{PersonID}

This is a quite common scenario. I have come across this many times I am sure many developers have. And fortunately creating such an API is not very time consuming. But still you have to write “some” code.

With LiteDB.AutoApi, you just need to create the model. Everything else, including presisting of data & exposing endpoints is done automatically by the library.

Here’s an example using dotnet core:

LiteDB.AutoApi example

This is useful as long as you don’t want to do anything custom. This was my attempt to share a small utility I created just in case anyone else needs to use it.

Thanks! & happy coding :)

Scala | Akka | Functional Programming | Distributed Systems

Scala | Akka | Functional Programming | Distributed Systems