Handling request body data
When working with Apex REST endpoints, Apex will parse any JSON and XML request bodies and response data automatically, when the method signature for the annotate method contains parameters to be deserialized to. In my experience, this is the easiest and most effective way of working with data in Apex REST and removes the need for data parsing from the endpoint itself. There are some situations, however, where this will not be possible and so it will be necessary for the endpoint to handle the parsing of data itself.
Recall the code we had for the HospitalRESTService.doPost()
method:
@HttpPost global static String doPost() { Â Â Â Â Id hospitalRTId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Hospital').getRecordTypeId(); Â Â Â Â List<API_Mapping__mdt> mappings = [SELECT DeveloperName, Â Â Â Â Target_Field__c FROM API_Mapping__mdt]; Â Â Â Â Blob...