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.

LWC to LWC Communication using Lightning Messaging Service (Part - 2)

In my previous post ( previous post link ) we have learn how to create a Lightning Messaging Service with 6 steps and today we will use the ...