How to use Ember-data to communicate with Web API (ASP.NET)

I have encountered some issues when connecting to the backend (WEB API).

HTTP Verb - GET is working, ember-data able to fetch the data, but it returned error 405 for the others Verb (POST, DELETE, PUT).

Thank you for any help.

Do you have control over your backend? If you’re using Web API, you’ll need to add an attribute to your controller actions to tell it which HTTP verb to use.

For example:

[HttpPost]
public async Task<IHttpActionResult> MyAction(RequestModel request)
{
   // code goes here
}

Check out this article on Web API 2, specifically the section on HTTP Methods.

Hi Mike,

Thanks for your reply.

Yes, I did add the attribute like the example attach, but still having the problem. I have tried to use ‘POSTMAN’ - REST Client to test the WEB API, everything is working, but it is no when using ember.

Hence, I suspect the error is caused by the client side instead of backend. I would like to know is there any standard way to achieve the communication between the ember-data with WEB API so that I able to refer to.

Thanks.

Your issue is going to be with WebAPI. Are you handling the content type properly? Does the controller action get triggered or does the failure happen before? Do you have an HttpMethodConstraint on the path in the WebApiConfig file? Try putting a breakpoint on the controller and debug.

I use Ember with Web API.