Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No HTTP resource was found that matches the request URI

I have checked some number of links to get understanding the cause of the error but not fixing my issue.

I am trying to access WebAPi action from Postman but getting the below error.

"message": "No HTTP resource was found that matches the request URI 'http://localhost:50684/api/albums/history'.",
"messageDetail": "No type was found that matches the controller named 'album'."

My API.

[Authorize]
public class AlbumsController : ApiController
{

   [HttpGet]
   [Route("api/album/history/")]
   public BaseTO GetHistory(string type,int id)
   {  
      //api stuff
   }
 }

I tried with api/album/history/{anything}

While making call from Postman I am passing:-

  • Authorization Token
  • Type
  • Id

Any help/suggestion highly appreciated. Thanks

like image 240
Kgn-web Avatar asked Feb 10 '17 09:02

Kgn-web


1 Answers

Have you enabled attribute routing in api config? config.MapHttpAttributeRoutes();

With your current route, you should hit it via query string http://localhost:50684/api/albums/history?type=test&id=1 and decorate the parameters with [FromUri]

[HttpGet]
   [Route("api/albums/history/")]
   public IHttpActionResult GetHistory([FromUri]string type,[FromUri]int id)
   {  
      //api stuff
   }

or to hit the api via route parameters - http://localhost:50684/api/albums/history/test/1

[HttpGet]
   [Route("api/albums/history/{type}/{id}")]
   public IHttpActionResult GetHistory(string type,int id)
   {  
      //api stuff
   }
like image 100
Developer Avatar answered Oct 05 '22 03:10

Developer