Introduction
While searching on net I came across many good articles about REST, But I was explicitly searching for a very basic start up example like - "Hello world" program for RESTful service. I got an idea about it from here, but this article is also an one elaborated for me.
In this article I am just showing to quickly set up a project in visual studio 2010 for RESTful service.
Step 1
Step 2
- Open New Project window and select online Templates button

Step 3
- Type WCF in Search box and enter. you will see WCF REST template 40 or above. Select this template.
Step 4
Now open your chrome browser and go to here (cREST client) to install a REST client tool. Alternatively you can go to web store of chrome and search "rest client", There are many REST client tools for chrome and similarly for mozilla also there are plugins available for REST clients.

Using the Code
The boilerplate code you will get after creating a new project will include a service class and a sample Item class. Sample Item represents the data structure that we are exposing in this service. Off course we should replace this class with our own class and implement the service methods.
Initially, we get a GetCollection method as a "Hello world"
method. Lets run this project now.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Service1
{
[WebGet(UriTemplate = "")]
public List<SampleItem> GetCollection()
{
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
}
[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
throw new NotImplementedException();
}
[WebGet(UriTemplate = "{id}")]
public SampleItem Get(string id)
{
throw new NotImplementedException();
}
[WebInvoke(UriTemplate = "{id}", Method = "PUT")]
public SampleItem Update(string id, SampleItem instance)
{
throw new NotImplementedException();
}
[WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
public void Delete(string id)
{
throw new NotImplementedException();
}
}
Step 5
Run the application and let the browser open with default page, since there is no web page in this application, A directory list will be showed.
Step 6
Copy the address of server from browser - http://localhost:4145/ (in my case) append the name of service class "service1" and paste this to GET text box of REST client in chrome .
Thats it, you should get a output in xml saying "Hello".