Skip to content
Jeroen Knoef edited this page Apr 29, 2014 · 3 revisions

If you want your urls to look different from the framework default, there are two ways to go about that. The easiest one is to call handleEvent() on the Context from within Application.cfc, instead of handleRequest(). While this will work, it is not very flexible if you need to change the way your urls look later on. To this end, the EndPoint is introduced.

EndPoint is an interface that defines the following methods:

  • collectParameters(): this method is invoked by Context when it starts the request cycle. This method should return a struct with the parameters that you want available on the event object. Specifically, the context looks for the keys target (string) and event (string) in that struct. That tells the context which event to dispatch to start handling the request.
  • createUrl(required string target, required string event, struct parameters): outputs a url. EndPoint is made available in views, so as long as you use this method everywhere you need a url, you can swap endpoints without trouble.

Your own endpoint implementation becomes active when you set it on the context:

application.context.setEndPoint(endpoint);

By default, the framework provides a strategy (DefaultEndPoint) that does the following:

  • collectParameters merges the url and form scope. Variables in the url scope take precedence.
  • createUrl outputs urls of the form: index.cfm?target=[target]&event=[event] followed by the parameters, if any.

A second endpoint implementation is the PathInfoEndPoint, which picks up the target and event from the path_info variable. The last part of the path is the event, all that precedes is the target. For example, in '/users/stuff/list', 'list' will be the event, and 'users/stuff' will be the target. Notice that the target has no leading slash (otherwise this slash would be needed for all targets).

Additionally, this endpoint supports REST.

Clone this wiki locally