I'm thinking about this too, building a REST back end for a Vue.js app, where all client requests have the content in the request body.
Unless I'm missing some relevant configuration option, the CB REST template still has each handler doing something like this in every REST-accessible method:
data = deserializeJSON(toString(getHTTPRequestData().content))
I'm surprised, since in general ColdBox is all about teaching the infrastructure about patterns like this. I'd expect something more like one this in /coldbox/system/web/services/RequestService.cfc.requestCapture():
1) Always check for a json request body if FORM and URL are empty (first 2 lines are the existing code):
if( isDefined( "FORM" ) ){ structAppend( rc, FORM ); }
if( isDefined( "URL" ) ){ structAppend( rc, URL ); }
if (structIsEmpty(rc))
{
requestBody = toString(getHTTPRequestData().content);
if (isJSON(requestBody))
structAppend(rc, deserializeJSON(requestBody));
}
2) Have an overridable detection method that examines some piece of request metadata to see if that's expected, for instance if Content-Type is application/json. If the client flags content in the request body differently, you'd override that method appropriately.
Am I missing how we're expected to implement such things, or some great reason why there's nothing built in out of the box? Could well be, I'm very new to ColdBox. Should I submit a PR with strategy #1?
Thanks,
Dave