Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack Backbone.Todos Delete 405 not allowed

I realized when click Backbone.Todos example "Clear x completed items" I get a DELETE 405 not allowed...

I understand from the pervious helps and docs that if I want to enable DELETE PUT PATCH ... I need to set

X-http-method-override : DELETE

if it was a form or in jquery.

But I am not sure how this is done in the Backbone.Todos example as I am new to backbone.js.

Could you please point out how to fix the DELETE 405 ? Thank you.

EDIT ---------------------------------------

I can always change routes to ...

[Route("/todos/add")] //C - post
[Route("/todos/{id}")] //R - get
[Route("/todos/{id}/edit")] //U - post
[Route("/todos/{id}/delete")] //D - post

So, only Post and Get are enough to do the job. But it doesn't look very Restful compare to:

[Route("/todos/{id}", "Delete")] //D - delete

Does it?

like image 909
Tom Avatar asked Oct 04 '12 08:10

Tom


1 Answers

Backbone.js has special support for this, which you can enable with:

Backbone.emulateHTTP = true

From their website:

emulateHTTP Backbone.emulateHTTP = true

If you want to work with a legacy web server that doesn't support Backbones's default REST/HTTP approach, you may choose to turn on Backbone.emulateHTTP. Setting this option will fake PUT and DELETE requests with a HTTP POST, setting the X-HTTP-Method-Override header with the true method. If emulateJSON is also on, the true method will be passed as an additional _method parameter.

Backbone.emulateHTTP = true;

model.save();  // POST to "/collection/id", with "_method=PUT" + header.

The 405 response may be the result of having something else running in IIS like WebDav that will hijack the and reject the request before it reaches ServiceStack. Otherwise if it's being rejected on the client you may want to enable CORS to allow additional HTTP Verbs to be sent.

like image 90
mythz Avatar answered Oct 11 '22 14:10

mythz