Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine route path from the controller in a method ASP.NET WEB API

I have an AppointmentController with a Route attribute and an HTTPGet method inside of it

[ApiController, Authorize]
[Route("api/[controller]")]
public class AppointmentController : ControllerBase 
{

    [HttpGet("/user/{userId:guid}")]
    public async Task<ActionResult<ApiResponse<IEnumerable<Appointment>>>> GetUserAppointments([FromRoute] Guid userId) {}

}

I want the route to be : "/api/appointment/user/:userId"

Instead I get "/user/:userId" in the Swagger UI

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is the problem here?

>Solution :

Just remove the forward slash / before your route "user/{userId:guid}"

[ApiController, Authorize]
[Route("api/[controller]")]
public class AppointmentController : ControllerBase 
{

    [HttpGet("user/{userId:guid}")]
    public async Task<ActionResult<ApiResponse<IEnumerable<Appointment>>>> GetUserAppointments([FromRoute] Guid userId) {}

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading