locked
WCF Service method implementation according to REST Verbs RRS feed

  • Question

  • Hi,

    I am facing some difficulties in understanding the relation between Service method implementation and relevant REST verbs. As I can understand follwing are actions of the REST verbs:

    [WebGet]

    GET resource

    [WebInvoke]

    POST adds resource

    PUT updates resource

    DELETE delete resource

    Now my question is, while I am using the verbs like POST/PUT/DELETE, its the implemented code in the service methods, which really matters. I mean, if I use DELETE verb in [WebInvoke] and implement some insert or update implementation in the relevant service method, still it will work without producing any errors. So, what role exactly the verbs plays here? Are the verbs used just sets a  standard specification and implementaion doesn't matters?

    Regards

    ronit_rc


    • Edited by ronit_rc Monday, April 30, 2012 6:53 AM
    Monday, April 30, 2012 6:52 AM

Answers

  • Imagine in the world of a type library (i.e., no services or networking involved). You can certainly write a method called InsertPerson(Person p) whose implementation will delete that person from the database and also delete some files from the current directory. It's your implementation, so you can really do whatever you want. That would be quite confusing for people who use your library. but what you're doing isn't technically wrong (you just decided to name the operation that way. I'd argue that this library would have been really bad designed, but that's something you can challenge.

    Similarly, you can make a DELETE operation add data, or a POST operation return something, but you'll be going against what people expect from the HTTP verbs. There are no "syntax" errors, but there will be an expectation mismatch on what your operations are doing. In some cases it's actually worse, as you'll be going against not only the expectation of people, but of some components as well - for example, GET requests are supposed to be indempotent and cacheable, so if you use a GET request to add something, it's possible that a proxy will returned a cached response and your request will never make to the final service.

    In short, nothing will force you to use the HTTP verbs as they were intended to be used, but you definitely should.


    Carlos Figueira

    Monday, April 30, 2012 4:20 PM

All replies

  • Imagine in the world of a type library (i.e., no services or networking involved). You can certainly write a method called InsertPerson(Person p) whose implementation will delete that person from the database and also delete some files from the current directory. It's your implementation, so you can really do whatever you want. That would be quite confusing for people who use your library. but what you're doing isn't technically wrong (you just decided to name the operation that way. I'd argue that this library would have been really bad designed, but that's something you can challenge.

    Similarly, you can make a DELETE operation add data, or a POST operation return something, but you'll be going against what people expect from the HTTP verbs. There are no "syntax" errors, but there will be an expectation mismatch on what your operations are doing. In some cases it's actually worse, as you'll be going against not only the expectation of people, but of some components as well - for example, GET requests are supposed to be indempotent and cacheable, so if you use a GET request to add something, it's possible that a proxy will returned a cached response and your request will never make to the final service.

    In short, nothing will force you to use the HTTP verbs as they were intended to be used, but you definitely should.


    Carlos Figueira

    Monday, April 30, 2012 4:20 PM
  •  Hi Carlos,

    Thanks a lot for the answer.

    Regards

    ronit_rc

    Tuesday, May 1, 2012 4:04 AM