ResourceMappings
Overview
Module
- package:
@aerokit/sdk/http - source: http/rs/mappings.ts
- last updated:
The ResourceMappings class is a core component of the HTTP controller module, responsible for managing the mappings between URL path templates and their corresponding resource handler specifications. It serves as the configuration store for the HttpController, allowing developers to define and manage their API resources in a structured manner.
Key Features:
- Resource Management: Allows defining resources with specific URL path templates and their associated handlers.
Use Cases:
- API Configuration: Developers can use ResourceMappings to configure their API endpoints, specifying the paths and the logic that should handle requests to those paths.
Example Usage:
import { ResourceMappings } from "@aerokit/sdk/http";
const resourceMappings = new ResourceMappings({
"users/{id}": {
get: (req, res) => { ... },
post: (req, res) => { ... }
},
"products/{id}": {
get: (req, res) => { ... },
post: (req, res) => { ... }
}
});Classes
ResourceMappings
path()
Creates or retrieves a Resource object corresponding to the given path. The second, optional argument can be used to initialize the resource.
tspath(sPath: string, oConfiguration: any): Resource;
Parameter Type Description sPathstringThe URL path template for the resource (e.g., "users/{id}"). oConfigurationanyOptional configuration object for initial resource setup. Returns
- Type:
Resource- Description: The created or existing Resource instance.
resourcePath()
Alias for path().
tsresourcePath(sPath: string, oConfiguration: any): Resource;
Parameter Type Description sPathstringoConfigurationanyReturns
- Type:
Resource- Description:
resource()
Alias for path().
tsresource(sPath: string, oConfiguration: any): Resource;
Parameter Type Description sPathstringoConfigurationanyReturns
- Type:
Resource- Description:
configuration()
Returns the compiled configuration object for all resources managed by this ResourceMappings. The configuration is structured to be consumed by the HttpController's routing logic.
tsconfiguration(): void;Returns
- Type:
void- Description:
readonly()
Removes all but GET resource handlers from all managed resources, making them read-only.
tsreadonly(): this;Returns
- Type:
this- Description: The ResourceMappings instance for method chaining.
disable()
Disables resource handling specifications matching the arguments, effectively removing them from this API.
tsdisable(sPath: string, sVerb: string, arrConsumes: any, arrProduces: any): this;
Parameter Type Description sPathstringThe path of the resource. sVerbstringThe HTTP verb (e.g., 'get', 'post'). arrConsumesanyArray of consumed media types. arrProducesanyArray of produced media types. Returns
- Type:
this- Description: The ResourceMappings instance for method chaining.
find()
Provides a reference to a handler specification matching the supplied arguments.
tsfind(sPath: string, sVerb: string, arrConsumes: any, arrProduces: any): any;
Parameter Type Description sPathstringThe path of the resource. sVerbstringThe HTTP verb (e.g., 'get', 'post'). arrConsumesanyArray of consumed media types. arrProducesanyArray of produced media types. Returns
- Type:
any- Description: The matching Resource handler specification or undefined.
