Working as an ISV where once a global
is packaged and installed the signature can't be changed, I've found this style of working very painful:
@RestResource(urlMapping='/V1/cases/*')
global with sharing class REST_cases_v1 {
@HttpGet
global static Case[] doGet(Id someId) {
Essentially the URL mapping, the inputs and the outputs are all fixed. So the only way to evolve is to add another class as John describes which then also means that you or your customer has to ensure that the new class is made visible in all the relevant profiles. (Permission sets can help.)
The pattern I now use instead is this one where the entry point classes once created never need to be replaced and the versioning logic - including the shape of the request and response objects - is entirely under the control of the programmer:
@RestResource(urlMapping='/cases/*')
global with sharing class REST_cases {
@HttpGet
global static void doGet() {
// Parse RestContext.request.requestBody
// Internal versioning logic based on requests data
// Serialize and set RestContext.response.responseBody
// and set RestContext.response.statusCode
}
}
The parsing/serializing is easy given that JSON.deserialize
and JSON.serialize
methods are available.