githubEdit

file-brackets-curlyREST 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, restDeleteApplication

  • Multiple 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/ )",
	...
}

Install the module on your initial server start

.server.json scripts block:

Seed your server directory with a dryRun start and update the web.xml file

Once the server is seeded, open the web.xml file in the server home ( e.g. {server-home}/WEB-INF/web.xml) and update the servlet-mapping section to add the url-pattern node for the REST prefix:

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

1. Create a REST-Enabled Component

2. Register Your REST Application

In your Application.cfc:

3. Access Your REST Endpoints

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:

  • Accept header for responses

  • Content-Type header for requests

Supported formats:

  • application/json, text/json

  • application/xml, text/xml

  • application/x-www-form-urlencoded

  • multipart/form-data

  • text/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?