0

I am working on a Web API project using Asp Net Core 2.1. My existing Web API has the following Get method (and numerous other methods like these):

[HttpGet("GetEmployeByName/{Name}")]
public Employee GetEmployeeByName(string name)
{... some code...}

This responds to the following incoming request:

http://localhost:8080/Employee/GetEmployeeByName/{Name}

Now my requirement is such that some of the APIs could be called by passing an additional id such as:

http://localhost:8080/Employee/{Id}/GetEmployeeByName/{Name}.

I still need to map it to the original method without changing the route. This can be done using ASP Net Core's feature of URL Rewrite and the URL can be re-written without the id.

However what i want to do is to capture the {Id} as well and save it to Session\ Context.

Does anyone know how to extract the id and rewrite the URL.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Sohanit
  • 1
  • 2

1 Answers1

-1

Maybe you can find what you need here optional parameters web api, you would need to add that parameter at the end as optional parameters always go at the end, also you could try to use both versions of the end point encapsulate the logic and reuse it on both versions.

hiram acebo
  • 119
  • 1
  • 9
  • I could have used that if i was still in the starting phases of the project. I have hundreds of APIs like these and don't want to modify the routes for them. Want some thing done in the pipeline before the request reaches the API methods – Sohanit Aug 03 '18 at 11:21
  • you should have specified pipeline in the question – hiram acebo Aug 03 '18 at 15:26