Routes distinction

Kuler Master 246 Reputation points
2021-10-10T19:49:31.083+00:00

Hello,

I have an existing route named bidding and it returns all opportunities in the system.
Then I have another route that is also named "bidding" and is of POST type. It is used for placing a single bid.
Finally I have one more action for placing multiple bids at once.

Do you think I should set the third action Route to be named by the action OR I should do something more efficient?

Thank you in advance!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,199 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,016 Reputation points Microsoft Vendor
    2021-10-11T02:05:31.307+00:00

    Hi @Kuler Master ,

    You can add the third action route, then each action route has the separate route to do the actions.

    [Note] For the same type of method, such as Post method, even the parameter is different, you should set the route constraint or use a different route template, because it will cause the 500 error: The request matched multiple endpoints.

    Besides, for the bidding route, in the post action method, you can use an array or list of bid as the parameter, then in the action method, you can base on the array or list to filter data and return the result, in this scenario, there only have two routes.

    Both the above methods are Okey, it depends on your choice.


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

  2. Kuler Master 246 Reputation points
    2021-10-11T06:03:59.59+00:00

    Thank you for the prompt reply (like)

    What I originally tried before posting the Q and couldn't achieve was the following:

    /api/bidding {GET}
    /api/bidding {POST} taking bid as param
    /api/bidding {POST} taking array of bids as param

    Swagger is erroring out with error 500 :(

    I've resolved it by setting Route for the second POST action e.g. [Route("[action]")]
    /api/bidding
    /api/bidding
    /api/bidding/{actionname}

    However, I don't like this and would be great if I could make the both POST actions to work with only api/bidding

    Thank you so much

    P.S. sorry for insisting on the third bidding but it's a must because it needs to be explained totally different than the single bidding.