In REST API, can we create multiple @Http Methods (for e.g. @HttpGet) annotations of the same type in a single class? i have a need where i need to write more than one get method in the same class? is that possible and if it is how?
One of my friend started debating with me that it is possible as long as the method signatures are different. For example,
@RestResource(urlMapping='/RestResearch/v1/Test')
global with sharing class RestResearch {
@HttpGet
global static String getAllCourses(String s) {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
System.debug('id :'+id);
return 'Success';
}
@HttpGet
global static String getMyCourses(String s1, String s2, String s3, String s4, String s5, String s6) {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
return 'Success';
}
}
But, i am getting an error "@HttpGet already used elsewhere in this class" if i tried to save it in Eclipse.
Any help is much appreciated...