Nick Kahn
Nick Kahn

Reputation: 20078

WebInvoke Method=“POST” or "GET" for a REST Service on WCF

When should use post vs get? in a REST service on WCF?, below is my interface

       [OperationContract]
       [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
       string DoLodge(string Id, Lodge value);

       [OperationContract]
       [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
       LodgeLevel[] GetLodgeLevels(string Id);

       [OperationContract]
       [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
       long GetLodgeCount(string Id);

Upvotes: 7

Views: 33599

Answers (4)

Shanka
Shanka

Reputation: 23

But in C#, you receive a response in GET. so the complete answer will be, GET should be used when retrieving an object from the server and used when sending an update back from the server.

Upvotes: 0

Justin Niessner
Justin Niessner

Reputation: 245429

POST should be used when sending an update back to the server.

GET should be used when retrieving an object from the server.

You might want to read up on what the HTTP Verbs mean in the context of RESTful services:

Upvotes: 15

Reed Cao
Reed Cao

Reputation: 21

GET: Get a collection of entries (as a feed document) or a single entry (as an entry document).

POST: Create a new entry from an entry document.

PUT: Update an existing entry with an entry document.

DELETE: Remove an entry.

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038890

POST everytime you are modifying some state on the server like database update, delete. GET for readonly fetching like database select.

Upvotes: 7

Related Questions