API FIRST

ColdBox has truly exceptional native REST capabilities which have been integrated with the RestHandler, a customizable Response object and a powerful URL Router into the core.

API First logo

This RestHandler will provide you with utilities and approaches to make all of your RESTFul services:

  • Uniformity for responses
  • Use a consistent and extensible response object
  • Provide consistent error handling
  • Provide Invalid route handling
  • Much more
component extends="coldbox.system.RestHandler"{

    function hello( event, rc, prc ){
        event
            .getResponse()
            .setData( "Hello from restful Land" )
    }
  
    function invalidData( event, rc, prc ){
		event
            .getResponse()
            .setErrorMessage(
                errorMessage : "invalid id sent",
                statusCode : 401
            )
    }
	
	function showData( event, rc, prc ){
		prc.data = service.getUsers()
		return prc.data
	}
	
	function myData( event, rc, prc ){
		prc.mydata = myservice.getData()
		return renderView( "main/myData" )
	}
  
}

Read more about the native REST capabilities in our documentation.