1

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.

2
  • I never tried any of it, but this article: Dynamic controller routing in ASP.NET Core 3.0 sounds like a possible solution or else could get you on the right path. Or maybe this article: Dynamic endpoint routing in asp.net Commented Dec 1, 2024 at 23:35
  • 1
    I think you can handle that with one endpoint and a route parameter, in your example the cars would be your route parameter and can use that to filter your query since your DB tables are fixed. Commented Dec 2, 2024 at 11:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.