Routing question - how opinionated is it?
@xuzhg is already working on this.
Since Jan 6, 2021.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
My team and I have an API working on netcore3.1 using the v7 OData library. We are experimenting with .NET 5 and the v8 preview and are trying to build the following structure;
Lets say we have User and Account entities. Account can contain many users.
The URLs should look like the following;
/accounts
Get all accounts
/accounts/{id}
Get one account
/users
Get all users
/users/{id}
Get one user
/accounts/{accountId}/users
Get all users in an account
I've gotten as far as creating a UsersController and AccountsController with a matching EDM model (whose entities are actually DTOs). This gives me /users and /accounts seemingly working, how would I go about implementing the other endpoints? Normally I'd just use [HttpGet("some_route")] but it looks like the OData stuff has a sort of alternate routing system using its own attribute [ODataRoute] which looks to be only partially documented, and the relationship between it and [HttpGet] etc. is quite unclear. I've tried using this but it seems to do nothing, I just get 404 responses.
I realise that our URL structure might not be exactly to the OData spec (e.g. accounts/{id} vs. accounts({id})) but I can't seem to get either working, and surely the point of having the attribute based routes is so we can choose our own?
In the v7 library we simply ignored all the EDM stuff (we aren't necessarily interested in having OData-based actions etc.) and just threw ODataQueryOptions<T> parameters on all the methods we needed OData query support for, using ApplyTo and Automapper to do the work, but this doesn't seem to work properly in v8, unless I'm misunderstanding something.
Any help would be much appreciated.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.