How to pass object to RESTful Service with GET request?

I have seen some posts in stackoverflow saying "sending list of items in the GET Method, is NOT allowed. It has to be accomplished via POST method only"

My code looks like

    [OperationContract]
    [WebGet(UriTemplate = "Employee/{emp}",RequestFormat=WebMessageFormat.Json)]
    Employee GetEmpDetails(string emp);

and my input json object will be "{'id':1,'name':'test',....} Is there any alternative way of achieving this issue.

Thanks

Answers


It is possible to send list of items with GET, it's just that out of the box only primitive values are supported. String values work just fine, but if you want to pass a complex object, you need to create a custom QueryStringConverter. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx explains how this can be done.


If you make your service RESTful you will most probably use HTTP PUT for Add method and HTTP POST for Update method. It is absolutely ok to pass object to these methods because objet will be part of HTTP request's body, not part of URI. URI is important for HTTP GET requests. HTTP GET requests should be only for data retrieval not for data modification.


You are mixing up HTTP GET/POST/... requests and REST GET/POST/PUT/DELETE/... When you wanna request something RESTfully - you do a GET request. In your case I think it should look like

employee/{id}

or

employee/{name}

Please also note that usage of lowercase in the URI is preferable. If you need multiple GET criteria, I think it could look like:

employee/id/{id}/name/{name}

Need Your Help

UIImageView/UILabel property is always nil when allocated and assigned directly

objective-c ios xcode

I have an UIImageView and an UILabel in my customized UIButton class.

is Milner'c CCS turing complete

concurrency lambda-calculus

So one can say a language is Turing complete if it meets some criteria. Milner's Calculus of Communicating Systems (CCS) is Turing complete. However, I could not find a proof for this. Is there any...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.