It does not matter if these were your inside projects or already commercial ones, you certainly created APIs many times and wrote the same CRUD methods all the time. We, developers, are lazy and like to make our lives easier and optimise our work. Jeffrey T. Fritz also made this assumption and created a brilliant library called InstantAPIs. What does it give us? How do we use it? I will answer these questions today.
As I mentioned, InstantAPIs is a library created by Jeffrey T. Fritz. You can use it for generating Minimal API endpoints for an Entity Framework context or based on a JSON file. In this blog post, I will focus on the first option.
DbContext based API
So we can generate all of the typical CRUD API endpoints with the Reflection approach. First of all, we need to create the builder and add the required services (InstantAPIs and SqlLite which is our provisional database):
And now it is time for a bit of magic and proceeds the power of InstantAPIs. 😉
And yeeees, that is it! In a few lines of codes our CRUD is ready:
Additionally, you have the option to customize the API if you wish. For instance:
The output for that case then is the following:
I have shown the majority of the usage part here to illustrate to you that it is easy and enjoyable. Feel free to explore it more! 🙂 It can be valuable for your daily work.