I have been using rest service and building them for long time but something which I am not clear is on the wildcard part.
Whenever I had to expose an Apex rest service I expose apex class with annotation like - @RestResource(urlMapping='/Cases/*')
. I do put '*'
at the end of
the URL , but I haven't discovered the use case for that.
Recently I just tried to build a REST service to understand the wildcard application:
@RestResource(urlMapping='/Cases/*')
global with sharing class CaseManager {
@HttpPost
global static ID createCase(String subject, String status,
String origin, String priority) {
Case thisCase = new Case(
Subject=subject,
Status=status,
Origin=origin,
Priority=priority);
insert thisCase;
return thisCase.Id;
}
}
I use workbench to test the above rest service by trying to create a Case record. I tried calling the apex service and used a JSON wiht POST method to create cases. All of the below URI worked to create a CASE using the service:
- /services/apexrest/Cases/cheese
- /services/apexrest/Cases/Dog
- /services/apexrest/Cases/man
I know since it is wildcard it can take any value for '*'
, but what is the significance of using different name for the wildcard when all of them does
the same job of creating a CASE record. Please enlighten me with an example if possible.