Svenmarim
Svenmarim

Reputation: 3735

REST API path parameters different types

I have a simple question, but I can not seem to find the answer somewhere on the internet.

When using path parameters in a REST API, are the following methods on different endpoints or will it conflict?

[HttpGet("{stringId}")]
public IActionResult GetObjectByStringId(string stringId) {
}

[HttpGet("{integerId}")]
public IActionResult GetObjectByIntegerId(int integerId) {
}

Upvotes: 0

Views: 198

Answers (1)

Munesh Kumar
Munesh Kumar

Reputation: 541

When you hit one of your above mentioned endpoint, it will give error i.e. "The request matched multiple endpoints." You can solve this by specifying the type like below

[HttpGet("{integerId:int}")]
public IActionResult GetObjectByIntegerId(int integerId) {
}

Upvotes: 1

Related Questions