Skip to content

Framework Integration Points

cfchris edited this page Apr 20, 2013 · 6 revisions

When Relaxation is processing a request, there are points where you can inject some of your own logic. These are done by assigning handlers to the framework in the form of pointers to functions.

Authorization Method

Relaxation can call a method you provide to check if a client is authorized to perform the action they have requested. To set this up, call the "AuthorizationMethod" setter when initializing the framework.

application.REST.setAuthorizationMethod( checkAuth )

Relaxation will call the configured method with one positional argument that looks like the following.

{
	"Bean":		"ProductService",
	"Method":	"getProductByID,
	"Path":		"/product/1/",
	"Pattern":	"/product/{ProductID}/",
	"Verb":		"GET"
}

This argument structure allows you to build your permissions around beans and methods or paths and verbs.

Your authorization method must return a boolean. A value of "true" will let Relaxation know the client is authorized. If your method return "false", then the client will get a response with status (403 Forbidden).

OnError Method

Relaxation can call a method you provide when an exception occurs. To set this up, call the "OnErrorMethod" setter when initializing the framework.

application.REST.setOnErrorMethod( handleError )

Relaxation will call the configured method with three positional arguments that looks like the following.

Arg 1 - (The native CF error.)
Arg 2 - (The matched "resource".)
	{
		"Bean":		"ProductService",
		"Method":	"getProductByID,
		"Path":		"/product/1/",
		"Pattern":	"/product/{ProductID}/",
		"Verb":		"GET"
	}
Arg 3 - (The argument collection. See https://github.com/cfchris/Relaxation/wiki/Argument-Collection-Details.)

Relaxation will not capture the result of your OnError method. So, it's return type does not matter.

If you let the request terminate normally, Relaxation will return status 500 with a JSON packet containing minimal error info.

If you are very particular about your error response, it's OK if your error handler aborts.

Clone this wiki locally