Reputation: 2717
If i implement a REST based WCF service, then as a Request i will just use my http url say fr example http://www.example.com/createuser/user1
Now, the data i need to post to the server would go as part of HttpRequest object itslef, is this correct if i am using post method?
Also as part of response what do i get, do i get just JSON which is what i want from response or an HttpResponse object, which has json as part of it's body?
Upvotes: 0
Views: 194
Reputation: 14935
First of all, your URL still seems as RPC style. The method name smells in the URL(createruser/user1).
Instead if your user as resource, then the collection of Users could be shown as following http://www.example.com/users (with HTTP get) which would give you all the users.
For a perticular user http://www.example.com/Users/User_Id with HTTP get Method
If you want to create a perticular user, then http://www.example.com/Users with HTTP Post.
Now, HTTP Post sends data in form collection, so the information to create a user would be sent as form data.
As for respone, the server can send you multiple form of respone. The client has to tell in accept headers what kind of Representation he would like for a perticular resource(it could be sepcified in url also like the twitter apis). The server, then can take the client request in consideration and server the response in the content type. There are other media types also other than JSON, XML and plain text
As for your HTTResponse object, it would depend what kind of technology you are using to make a requeset. If you are using C#, then you would get a HTTPResponse object. If Javascript then you would get response, embedded inside XMLHttpRequest body(either by responseXML or responseText)
EDIT You could use Rest StarterKit for WCF or even you could use WebAPI. In WCF, while declaring your operation contract, you would annotate your method with following attributes
[OperationContract]
[WebInvoke(Method="GET", UriTemplate="/GetData",
ResponseFormat=WebMessageFormat.Json)]
string GetData();
What does it tells
Method = "GET" http method used for this resource
UriTemplate = for mapping the method to URL. A perticular URL needs a perticular method to be invoked.
ResponseFormat = Server to return the response in this format.
You could find more details over here and here
Upvotes: 1
Reputation: 4340
I don't know how you are going to implement the RESTful service, but i would recommend WebAPI. you can look at this example that shows how to do that, and you can see there the way the clients (web browsers) will show the responses.
If you meant that as a client you want to send requests to the service and you want to know how to do that then you have a few options.
I guess you are using .net for doing that so i two options you can use are:
Upvotes: 0