Wednesday, May 10, 2017

Rest Web Service Apex Code Sample.

Generally there are 6 annotation used to expose an Apex class as a RESTful Web service.

  1. @RestResource(urlMapping='/yourUrl') ==> This should be used above class declaration. Where value of urlMapping denotes your endpoint.
  2. @HttpDelete ==>  This should be used above web method declaration.
  3. @HttpGet ==>  This should be used above web method declaration.
  4. @HttpPatch ==>  This should be used above web method declaration.
  5. @HttpPost ==>  This should be used above web method declaration.
  6. @HttpPut ==>  This should be used above web method declaration.


Scenario : Create a simple rest web service, which has a simple web method which will return a string as a response.

Solution: Below code base is a simple rest web service example in Apex.
Now for simplicity, we are simply used @HttpGet annotation for the below web method.

/**
 * Rest Web Service Example.
 **/
@RestResource(urlMapping='/RestWSSampleExmpl/*')
global with sharing class RestWSSample
{
 @HttpGet
 global static String getRestSampleResponse()
 {
  return 'Success Response.';
 }
}

Note: Apex REST supports two formats for representations of resources: JSON and XML.

Data Cloud Part 6: Practical (Ingest Physical Store's Customer details and Sales details)

Hope you have already created your Data Cloud Org and also downloaded the Customer's details and Sales details from previous posts.  Now...