Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Use PATCH verb instead of PUT for "update" #50

Open
SlyNet opened this issue Mar 20, 2012 · 12 comments
Open

Use PATCH verb instead of PUT for "update" #50

SlyNet opened this issue Mar 20, 2012 · 12 comments

Comments

@SlyNet
Copy link
Contributor

SlyNet commented Mar 20, 2012

Rails chaned PUT to Patch for updates. Here are some details rails/rails#348
Should we make the same change?

@khalidabuhakmeh
Copy link
Collaborator

Thanks SlyNet,

I've heard about this, sadly I'm not sure we can make the same changes unless the MVC framework supports it. Looking through the HttpVerbs enumeration in System.Web.Mvc it looks like we are limited to what we have. I agree that patch is probably better, but not sure how to proceed. Any ideas?

@kirillsalykin
Copy link

We CAN made it, because string representation is used, so if we need PATCH support with can use "PATCH" without any enums. This could be done easily, just adding an alias for put methods.

@SlyNet
Copy link
Contributor Author

SlyNet commented Mar 20, 2012

I've checked code. Changes need to be made:

  • AdditionalAction.cs should have array of strings instead of array of HttpVerbs.
  • In the ResourceMapper.cs method is needed similar to current MemberRoute but that accepts params string[] as methods
  • GenerateRoute method already accepts array of strings not array of verbs.

Not sure that its all. But anyway in order to support it HttpVerbs enum is not appropriate

@khalidabuhakmeh
Copy link
Collaborator

Could you try making those changes and see if they work in a new development environment. My only concern is that Patch isn't turned on initially in IIS, which could create a frustrating experience for developers using this library. In addition, this could be a big breaking change for most people using this library so I wonder what kind of number bump it should get.

@SlyNet
Copy link
Contributor Author

SlyNet commented Mar 20, 2012

Afraid of the same. Its super breaking change. As for initially enabled verbs - PUT and DELETE are not enabled in IISExpress either

@kirillsalykin
Copy link

Well, i guess it is not pulblic api. So changes should not be breaking. And i guess there should be support for both put and patch verbs.

@khalidabuhakmeh
Copy link
Collaborator

Let's reach out to the MVC team and see if they are willing to add support for Patch. If they do, then this makes the transition seamless to support it, since it would just mean the addition of the Http Patch enum and a route constraint for Patch. Does that seam like a reasonable way to proceed?

The next changes to Restful Routing will probably be making sure it works with MVC4.

@SlyNet
Copy link
Contributor Author

SlyNet commented Mar 20, 2012

Agree with that. The main concern for me is if it works with WebAPI. See no reason why it should not work with regular actions/controllers

@khalidabuhakmeh
Copy link
Collaborator

I submitted a patch to asp.net mvc to support PATCH, so hopefully they accept it. On another note for myself.

PUT requests to /users/:id in Rails 4.0 get routed to update as they are today. So, if you have an API that gets real PUT requests it is going to work.

In Rails 4.0, though, the router also routes PATCH requests to /users/:id to the update action.

So, in Rails 4.0 both PUT and PATCH are routed to update.

@khalidabuhakmeh
Copy link
Collaborator

Patch will be supported in ASP.Net MVC 4 RC. So we should be able to mimic this.

@SlyNet
Copy link
Contributor Author

SlyNet commented Apr 5, 2012

Yes. I've seen that your pull request was accepted. Its just so cool! :)

@matthewp
Copy link

I actually would like to have both.

PATCH is for updating a resource, PUT is for replacing it. So when I get a PATCH, I know that my code should only change the form fields, where as when there is a PUT I know to replace the entire resource.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants