How to Create a Public RESTful Web Service on a Force.com Site

Trey AroseSalesforce, Technical TipsLeave a Comment

How to Create a Public RESTful Web Service on a Force.com Site

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.

  1. Navigate to Your Name | Setup | Develop | Sites  
  2. Click the name of the site you want to control.
  3. 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}

Leave a Reply

Your email address will not be published. Required fields are marked *