I'm looking for a solution to generate new API endpoints at runtime using ASP.NET Core 8. I'm open to generating controllers classes on the fly, using Minimal API or whatever other solution there is available.
I've also already looked into ApiFramework, but their documentation seems to very minimal and the .NET version referenced in there is 3.1.
My use case is as follows: I have a databases with two tables
- EntityType
- Id
- Name
- Field
- Id
- EntityTypeId (reference to EntityType)
- Name
At any time, an additional EntityType with the corresponding fields may be added. Let's say I add an entity type Car with two fields Mileage and Door count. I'd need to add an endpoint /cars that outputs data like this:
[
{
"Mileage": "xxx",
"Door count": "xxx"
}
]
I know how to generate a Type for this dynamically and how to fill out its values from the database, all that's left is providing a strongly typed endpoint, an I am at a loss on how to do this.
carswould be your route parameter and can use that to filter your query since your DB tables are fixed.