For the complete documentation index, see llms.txt. This page is also available as Markdown.

Web Support

Mock HTTP exchanges for testing web applications in BoxLang CLI runtime without a web server.

Mock web server for testing BoxLang web applications in CLI runtime. Simulates HTTP requests/responses without needing an actual web server.

โš ๏ธ Warning

DO NOT install this module into a BoxLang web-runtime! This module is for CLI runtime testing or mocking only and will cause JAR conflicts in web server environments. Not needed for CommandBox or MiniServer.

๐Ÿ“ฆ Installation

# OS Quick Installer
install-bx-module bx-web-support

# CommandBox
box install bx-web-support

โš™๏ธ Configuration

Configure in your ModuleConfig.bx:

settings = {
    port       : 8080,                          // Mock server port
    host       : "localhost",                   // Mock server host
    webRoot    : server.java.executionPath,    // Web root path
    secure     : false,                         // Enable HTTPS
    requestKey : "bxMockServer"                 // Request scope key
};

๐Ÿš€ Quick Start

๐Ÿ”ง BIF Reference

mockServerGet()

Creates or retrieves cached mock server exchange.

Arguments:

  • webroot (string) - Web root path

  • host (string) - Server host (default: localhost)

  • port (numeric) - Server port (default: 8080)

  • secure (boolean) - Enable HTTPS (default: false)

  • force (boolean) - Force new instance (default: false)

Returns: MockHTTPExchange

mockRequestNew()

Creates mock request builder for fluent configuration.

Arguments:

  • method (string) - HTTP method (default: GET)

  • path (string) - Request path (default: /)

  • body (string) - Request body

  • contentType (string) - Content type (default: text/html)

  • headers (struct) - Request headers

  • urlScope (struct) - URL parameters

  • formScope (struct) - Form fields

  • cookieScope (struct) - Cookies

  • Plus: webroot, host, port, secure

Returns: MockHTTPExchange (builder pattern)

mockRequestRun()

Executes full mock request with all-in-one configuration.

Arguments:

  • Request: path, method, pathInfo, queryString, contentType, body, urlScope, formScope, cookieScope, headers

  • Response: responseStatus, responseContentType, responseBody, responseHeaders

  • Server: webroot, host, port, secure, force

Returns: MockHTTPExchange (executed)

๐Ÿ’ก Examples

Basic GET Request

POST with JSON

Request with Authentication

Form Submission

๐Ÿ”— Fluent API

MockHTTPExchange provides fluent methods for request configuration:

Request Configuration:

  • setRequestMethod(method) - Set HTTP method

  • setRequestPath(path) - Set request path

  • setRequestBody(body) - Set request body

  • setRequestBodyJSON(struct) - Set JSON body (auto content-type)

  • setRequestBodyXML(string) - Set XML body (auto content-type)

  • setRequestContentType(type) - Set content type

Headers & Parameters:

  • addRequestHeader(name, value) - Add single header

  • addRequestHeaders(struct) - Add multiple headers

  • addURLParam(name, value) - Add URL parameter

  • addURLParams(struct) - Add multiple URL parameters

  • addFormField(name, value) - Add form field

  • addFormFields(struct) - Add multiple form fields

  • addRequestCookie(name, value) - Add cookie

Execution & Inspection:

  • execute() - Execute the request

  • getResponseBody() - Get response body

  • getResponseStatus() - Get status code

  • getMockRequestHeaders() - Get request headers

  • getMockResponseHeaders() - Get response headers

  • getMockForm() - Get form scope

  • getMockURL() - Get URL scope

Test Utilities:

  • clearRequestData() - Reset request data

  • clearResponseData() - Reset response data

  • clearAll() - Reset everything

๐Ÿงช Testing Patterns

Test Isolation

Multiple Requests

Response Inspection

๐Ÿ“š Resources

Last updated

Was this helpful?