MuggySoft
MuggySoft

Reputation: 1

WebAPI no HTTP resource found

So i have setup an ASP.NET WebAPI app and whenever i try to call the API i get this message:

<Error>
  <Message>
    No HTTP resource was found that matches the request URI    
   'http://localhost:62834/api/PiDBTest'.
  </Message>
  <MessageDetail>
    No type was found that matches the controller named 'PiDBTest'.
  </MessageDetail>
</Error>

I have tried a few different urls to get to call the API but still cant get anywhere with it. I have been using the following url to call the API

http://localhost:62834/api/PiDBTest

Can't seem to see why I'm not getting any success from the call?

Below is the code for the API controller and the RouteConfig

PiDBTest:

public class PiDBTest : ApiController
{
    private pidbEntities db = new pidbEntities();

    // GET: api/PiDBTest
    public IQueryable<PiData> GetPiDatas()
    {
        return db.PiDatas;
    }
}

RouteConfig:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}

Upvotes: 0

Views: 1351

Answers (4)

Hemanth Vatti
Hemanth Vatti

Reputation: 85

In my case, the controller class name didn't include the word "Controller" in it. I changed the class name from "Vendor" to "VendorController" then it started working.

Upvotes: 0

Dewz
Dewz

Reputation: 266

Please try change your API class as follows,

    public class PiDBTestController : ApiController
    {
        private pidbEntities db = new pidbEntities();

        // GET: api/PiDBTest
        [HttpGet]
        [Route("")]
        public IQueryable<PiData> GetPiDatas()
        {
            return db.PiDatas;
        }
     } 

Upvotes: 1

DrScrum Milestone
DrScrum Milestone

Reputation: 277

Could you add [HttpGet] on top of your Method public IQueryable GetPiDatas()

Upvotes: 0

Nkosi
Nkosi

Reputation: 246998

With attribute routing enabled, this will work.

[RoutePrefix("api/PiDBTest")]
public class PiDBTest : ApiController
{
    private pidbEntities db = new pidbEntities();

    // GET: api/PiDBTest
    [HttpGet]
    [Route("")]
    public IQueryable<PiData> GetPiDatas()
    {
        return db.PiDatas;
    }
}

Upvotes: 2

Related Questions