Manson
Manson
CC#
Created by Manson on 1/17/2023 in #help
How to differentiate endpoints based on parameters?
I want to have two endpoints /users and /users?id=#, but swagger doesn't seem to like what I have now. I really don't want to have to make an endpoint just because it can't differentiate between the two. Tips would be appreciated.
c#
// GET - "https://localhost:7229/api/users"
[HttpGet]
public async Task<IActionResult> GetAllUsers();

// GET - "https://localhost:7229/api/users?=#"
[HttpGet]
public async Task<IActionResult> GetUserById([FromQuery] int id);

c#
// GET - "https://localhost:7229/api/users"
[HttpGet]
public async Task<IActionResult> GetAllUsers();

// GET - "https://localhost:7229/api/users?=#"
[HttpGet]
public async Task<IActionResult> GetUserById([FromQuery] int id);

5 replies