RestHandlerand a customizable
Responseobject into the core. This
RestHandlerwill provide you with utilities and approaches to make all of your RESTFul services:
coldbox.system.RestHandler, directly via
extends="coldbox.system.Resthandler"or our using the
aroundHandler() provided in the
RestHandlerwill intercept all rest calls in order to provide consistency and uniformity to all your actions. It will try/catch for major known exceptions, time your requests, add extra output on development and much more. Here are a list of the features available to you:
onAnyOtherException()action. This action will log automatically the exception with extra restful metadata according to the environment you are executing the action with. It will also setup an exception response for you.
developmentenvironment it will set the following headers for you in the response object automatically.
x-response-time: The time the request took in CF
x-cached-response: If the request is cached via event caching
aroundHandler()is also smart in detecting the following outputs from a handler, which will ignore the REST response object:
Responseobject is used by the developer to set into it what the response will be by the API call. The object is located at
coldbox.system.web.context.Responseand can be retrieved by the request context object's
Responseobject has the following properties you can use via their getters and setter methods.
STATUS_TEXTSpublic struct exposed so you can use it for easy status text lookups:
RestHandlerthen you will have to create your own base handler that inherits from it. Then all of your concrete handlers will inherit from your very own handler.
coldbox.system.web.context.Responseand the rest handler constructs it by calling the request context’s
getResponse() method. The method verifies if there is a
prc.responseobject and if it exists it returns it, else it creates a new one. So if you would like to use your very own, then just make sure that before the request you place your own response object in the
preProcess()interceptor. Create a simple interceptor with commandbox e.g
prcscope, ColdBox will utilize it. Just make sure that your custom Response object satisfies the methods in the core one. If you want to modify the output of the response object a good place to do that would be in the
getDataPacket()method of your own
MyResponseObject. Just make sure this method will return a