Railo ReST API - Locating the Resource

 

Every Resource needs a unique URL eg /rest/api/person/123. The URL /rest/api/person can return a collection of resources, and is used to create a new one.

The attribute 'restpath' on component and function is to map the URL to a function to execute. The restpath on function is appended to the restparth of component. So a CFC to handle the person resource would have

    component restpath='/persons'
    function name='getPersons' restpath="/{id}"


Remembering Railo uses /rest to identify the request as a restcall, and a rest resource mapping has been added, eg /api

Curly brackets defines a placeholder for an argument that can only be used on a function.

    remote any function getPerson
        (
            required string id restargsource="Path"
        ) 
        restpath="/{id}" 

The attribute 'restargsource' on ARGUMENT tells Railo where the data can be located. The options are

  • path
  • query
  • form
  • cookie
  • header
  • matrix

A default can be added to argument as per usual.