Just started my first WCF rest project and would like some help on what are the best practices for using REST.
I have seen a number of tutorials and there seems to be a number of ways to do things…for example if doing a POST, I have seen some tutorials which are setting HttpStatusCodes (OK/Errors etc), and other tutorials where they are just returning strings which contain result of the operation.
At the end of the day, there are 4 operations and surely there must be a guide that says if you are doing a GET, do it this way, etc and with a POST, do this…
Any help would be appreciated.
JD
UPDDATE
Use ASP.NET Web API.
OK I left the comment
REST best practices: dont use WCF REST. Just avoid it like a plagueand I feel like I have to explain it.One of the fundamental flaws of the WCF is that it is concerned only with the Payload. For example
FooandBarare the payloads here.This is one of the tenants of WCF so that no matter what the transport is, we get the payload over to you.
But what it ignore is the
context/envelopeof the call which in many cases transport specific – so a lot of the context get’s lost. In fact, HTTP’s power lies in its context not payload and back in the earlier versions of WCF, there was no way to get the client’s IP Address innetTcpBindingand WCF team were adamant that they cannot provide it. I cannot find the page now but remember reading the comments and the MS guys just said this is not supported.Using WCF REST, you lose the flexibility of HTTP in expressing yourself clearly (and they had to budge it later) in terms of:
The new Web API, Glenn Block is working addresses this issue by encapsulating the payload in the context:
But to my test this is not perfect and I personally prefer to use frameworks such as Nancy or even plain ASP NET MVC to expose web API.