Correct Answer: C
To expose an Apex class as a RESTful web service, you use the @RestResource annotation.
Option C: @RestResource(urlMapping='/myService/*')
@RestResource Annotation:
The @RestResource annotation is used to define an Apex class as a RESTful web service, specifying the URL mapping.
Methods within the class are annotated with @HttpGet, @HttpPost, @HttpPut, etc., to handle HTTP requests.
Example:
apex
Copy code
@RestResource(urlMapping='/myService/*')
global with sharing class MyRestService {
@HttpGet
global static String doGet() {
// Implementation
}
}
Reference:
"Use @RestResource to expose an Apex class as a RESTful web service."
- Apex Developer Guide: Exposing Apex Classes as REST Web Services
Why Other Options Are Incorrect:
Option A: @HttpInvocable
There is no @HttpInvocable annotation in Apex.
Option B: @RemoteAction
Used to expose methods to JavaScript in Visualforce pages, not for REST services.
"@RemoteAction methods enable you to call methods in Apex controllers from JavaScript code in a Visualforce page."
- Apex Developer Guide: Remote Action Methods
Option D: @AuraEnabled(cacheable=true)
Used to expose Apex methods to Lightning components, not for REST services.
Conclusion:
Using @RestResource with a URL mapping is the correct way to expose an Apex class as a RESTful web service.