REST Compat +
A comprehensive CFML RESTful services compatibility module for BoxLang that provides compatibility for the CFML REST implementations
BoxLang REST Compatibility Module
A comprehensive CFML RESTful services compatibility module for BoxLang that provides compatibility for the CFML REST specification including routing and serialization
Overview
This module provides CFML-compatible REST services for BoxLang web applications, supporting:
RESTful Service Discovery & Registration: Automatic discovery and registration of REST-enabled CFCs
Intelligent Routing: Path-based routing with support for path parameters, query strings, and HTTP method matching
Content Negotiation: Automatic serialization/deserialization based on Accept and Content-Type headers
OpenAPI Documentation: Auto-generated OpenAPI 3.0 documentation for all registered services
CF-Compatible BIFs:
restInitApplication,restSetResponse,restDeleteApplicationMultiple HTTP Methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
Rich Annotations Support: All standard CF REST annotations including
httpMethod,produces,consumes,restPath,restArgSource
Installation
Add a servlet pass predicate which will match your default entry prefix in the web section of your server.json
"web":{
"servletPassPredicate":"regex( '^/(.+?\\.cf[cms])(/.*)?$' ) or regex( '^/(.+?\\.bx[sm])(/.*)?$' ) or path-prefix-nocase( /rest/ )",
...
}Add a web.xml override to your server.json to allow the servlet to pass REST routes to BoxLang
Place the following in a file ( for example .rest-override.xml ). Note the presence of the XML namespaces. They are required.
Then update your server.json to point to your override file - which will append to the existing servlet mappings
Update your server file to install the module on your initial server start
server.json scripts block:
Start your server and go!
Configuration
The following configuration items are supported and can be configured in the modules block of your boxlang.json or .cfconfig.json file:
Quick Start
Built-in Functions (BIFs)
restInitApplication()
Registers a REST application directory.
Example:
restSetResponse()
Sets a custom HTTP response with status, content, and headers.
restDeleteApplication()
Removes a registered REST application.
OpenAPI Documentation
Access auto-generated OpenAPI 3.0 documentation:
The documentation includes:
All registered services and routes
HTTP methods and paths
Request parameters and their types
Response schemas
Content types (produces/consumes)
Advanced Features
Path Parameters
Access as: /api/users/123
Custom HTTP Status Codes
Content Negotiation
The module automatically handles content negotiation based on:
Acceptheader for responsesContent-Typeheader for requests
Supported formats:
application/json,text/jsonapplication/xml,text/xmlapplication/x-www-form-urlencodedmultipart/form-datatext/plain
Error Handling
The module automatically returns appropriate HTTP status codes:
200 OK - Successful response with body
204 No Content - Successful response without body
400 Bad Request - Missing required parameters
404 Not Found - No matching route
405 Method Not Allowed - HTTP method not supported for route
406 Not Acceptable - Cannot produce requested content type
415 Unsupported Media Type - Cannot consume request content type
500 Internal Server Error - Exception during processing
Compatibility
This module implements the CFML RESTful services specification as documented in: https://helpx.adobe.com/CFML/developing-applications/changes-in-CFML/restful-web-services-in-CFML.html
Supported features:
✅ REST component and function annotations
✅ HTTP method binding
✅ Path parameters and routing
✅ Content negotiation
✅ JSON and XML serialization
✅ Custom responses
✅ Parameter sources (Path, Query, Form, Header, Cookie, Body)
✅ restInitApplication, restSetResponse, restDeleteApplication BIFs
⚠️ Subresource locators (partial - basic implementation complete)
⚠️ Custom serializers (not yet implemented)
Ortus Solutions, Corp https://www.ortussolutions.com
Last updated
Was this helpful?
