First time I’m trying to send data back to my API (asp.net web api)
My POST method get hit in the api when I do this: const newThing = this.store.createRecord(‘something’, { id: 123, name: “some name” }); newThing.save(); However, when I do a PUT I get a 405 error. Chrome and Edge display the error differently, but seems Edge are more clear:
Error: Ember Data Request PUT http://localhost/site/api/things/865 returned a 405 Payload (application/json; charset=utf-8) HTTP405: BAD METHOD - The HTTP verb used is not supported. (XHR): PUT - http://localhost/site/api/things/865
I realize I can post by adding some test code to the action a button click call.
The PUT happend when I have this action on my submit button:
{{action "saveThing" model}}
and then in the saveThing method in my route:
saveThing(thing) {
thing.save();
Apologies if this is not enough information, I’m still very new to Ember, first time trying to save something to an asp.net web api (which is hosted in localhost, but i am debugging in VS so can see if the post/put/get methods are being hit)
For what it help, my action methods in the api now just look like this
[HttpPost]
[Route("api/things")]
public HttpResponseMessage Post([FromBody] SomeDto someDto)
{
return new HttpResponseMessage()
{
Content = new StringContent("POST: Test message")
};
}
[HttpPut]
[Route("api/things")]
public HttpResponseMessage Put([FromBody] SomeDto someDto)
{
return new HttpResponseMessage()
{
Content = new StringContent("PUT: Test message")
};
}