HTTP Testing Methods

If you are building RESTFul services or you want to be able to simulate requests with other HTTP verbs that are not GET, then we have created a set of methods so you can test ANY HTTP method, param and even request headers.

request()

The request() method is the method to use to simulate ANY HTTP verb operation and get a response rendered into the request context. Please note that it expects a route and not an event. This means that it will also test your URL mappings, so make sure you pass the right URL.

/**
 * Shortcut method to making a request through the framework.
 *
 * @route The route to execute.
 * @params Params to pass to the `rc` scope.
 * @headers Custom headers to pass as from the request
 * @method The method type to execute.  Defaults to GET.
 * @renderResults If true, then it will try to do the normal rendering procedures and store the rendered content in the RC as cbox_rendered_content
 * @withExceptionHandling If true, then ColdBox will process any errors through the exception handling framework instead of just throwing the error. Default: false.
 * @domain                Override the domain of execution of the request. Default is to use the cgi.server_name variable.
 */
function request(
	string route                  = "",
	struct params                 = {},
	struct headers                = {},
	string method                 = "GET",
	boolean renderResults         = true,
	boolean withExceptionHandling = false,
	domain                        = cgi.SERVER_NAME
)

get()

post()

put()

patch()

delete()

Examples

Last updated

Was this helpful?