In the following tutorial we make a simple RESTful Web Service on a Force.com site. So lets get started, we will first create a Apex class by navigating to Your Name | Setup | Develop | Apex Classes | New
Below is the Apex code,
@RestResource(urlMapping=’/myservice’)
global class MyService {
@HttpGet
global static String doGet() {
String name = RestContext.request.params.get(‘name’);
return ‘Hello ‘+name;
}
}
Now the next step is to make this Apex class accessible via Public URL.
- Navigate to Your Name | Setup | Develop | Sites
- Click the name of the site you want to control.
- Click Public Access Settings to open the Profile page for your site profile and navigate to Enable Apex Class Access options .
Now we will enable the MyService Apex Class we created earlier.
By default the public URL for Apex REST has the format {Site_URL}/services/apexrest/{URL_mapping}