0

When i created one URL in WEB.API i got something like this

http://loaclhost/communities?userid=1

but i need something like

http://loaclhost/communities/1

Is it possible?

Update:

I go the answer thanks to @midhun-p.

Some error handling :

  1. Invalid 'WebDAV' module--> Take Help from HelenaG Grulichova.
  2. 404 mehtod not foud --> add routes.MapMvcAttributeRoutes(); in RouteConfig.cs.
Chanikya
  • 476
  • 1
  • 8
  • 22

2 Answers2

2

Yes.Decorate your API method with HttpGet Attribute and add Route parameter. Example code below .

    [HttpGet]
    [Route("communities/{userid}")]
    public string communities(int userid)
    {
        //your code
    }

you can call this api as http://loaclhost/api/controllername/communities/1

Midhun P
  • 126
  • 1
  • 11
1

Using Attribute routing you can decorate the method API as you wish.

Check the below links. https://www.c-sharpcorner.com/UploadFile/bhushangawale/attribute-based-routing-in-Asp-Net-mvc-5/ https://exceptionnotfound.net/attribute-routing-vs-convention-routing/