Closed
Description
Framework: netcoreapp3.1
I'm having trouble setting up an API with a unique routing structure. I've intentionally kept the API as simple as possible to explain my problem clearly. If this repo is not the correct place to ask this question, please redirect me to the proper location. I've put together a github sample, which I've been working in to try and get this working.
The API I'm trying to achieve is the follow:
GET ~/api/v1/Contexts({contextId})/Applications
GET ~/api/v1/People
Note that the Contexts({contextId})
segment isn't related to the Application Entity, but rather a logic step in the API to retrieve a group of Applications, segregated by context.
I've tried doing this in two ways:
- Register two routes as part of
UseMvc
. This allows me to specify the two routePrefixes, for api/v1 and api/v1/Contexts({contextId}). The problem with this is that a call toMapVersionedODataRoutes
, configures routes for all of the controllers. Thus by making two calls toMapVersionedODataRoutes
, I end up with
GET ~/api/v1/Contexts({contextId})/Applications
GET ~/api/v1/Applications
GET ~/api/v1/Contexts({contextId})/People
GET ~/api/v1/People
- One call to
MapVersionedODataRoutes
, but somehow use Attributes to specify theContext({contextId})
prefix for the Controller(s) that need it. This option seemed to be the correct approach, but I hit a snag with the EDM specifications, when added theContexts({contextId})
prefix. I tried using theODataRoutePrefix
attribute on the controller, like[ODataRoutePrefix("Contexts({contextId})/Applications")]
, but this produces at ODataUnrecognizedPathException for the segment Contexts, because I haven't registered the Contexts EntitySet (which I don't want to do, because it doesn't represent an Entity).
Any advice to help me achieve this design would be much appreciated!