Registry / api / tramway-formatter-hateaos

tramway-formatter-hateaos

JSON →
library0.5.0jsnpmunverified

A response formatter for the Tramway framework that creates HAL/HATEAOS-compliant REST APIs (v0.5.0). It includes a HATEAOSFormatter for requests, a MimeTypeResolver to handle different content-type headers, and a paginated variant for pagination. Requires tramway-core-router ^3.3.0. Provides decorator for APIProvider to automatically convert HATEAOS responses to standard Collection/Entity objects.

npm install tramway-formatter-hateaos
INSTALL
IMPORT
SIG · TRAMWAY-FORMATTER-
T
tramway-formatter-hateaos
apijavascriptv0.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

services
import { services } from 'tramway-formatter-hateaos';
const services = require('tramway-formatter-hateaos').services;
This export is an object containing service declarations for dependency injection (DI) container. Use named import for ESM. CommonJS require may work but is less idiomatic.
providers
import { providers } from 'tramway-formatter-hateaos';
const { providers } = require('tramway-formatter-hateaos');
Contains HATEAOSAPIProvider, a decorator for APIProvider. Named import for ESM.
HATEAOSEntity
import { HATEAOSEntity } from 'tramway-formatter-hateaos';
Named export for the HATEAOS entity class. CommonJS require also works.
HATEAOSCollection
import { HATEAOSCollection } from 'tramway-formatter-hateaos';
Named export for the HATEAOS collection class.

Demonstrates how to import and register the Tramway HATEAOS Formatter services and providers in a dependency injection container for REST API formatting.

// Assuming ESM environment with tramway-core-router set up import { services } from 'tramway-formatter-hateaos'; // Use services object to register DI in your config/services/index.js // Then access HATEAOSFormatter in a controller: // this.formatter.formatEntity(entity); // this.formatter.formatCollection(collection); // this.formatter.send(res, formattedItem, options); // For paginated variant, use 'hateoas.service.formatter:paginated' in DI. // To use HATEAOSAPIProvider: import { providers } from 'tramway-formatter-hateaos'; const { HATEAOSAPIProvider } = providers; // Register in DI: // "provider.hateaos": { // "class": HATEAOSAPIProvider, // "constructor": [ // {"type": "service", "key": "provider.api"}, // {"type": "service", "key": "factory.hateaos"}, // {"type": "parameter", "key": "api_resource"} // ] // }
Debug
Known issues
breakingRequires tramway-core-router version ^3.3.0. Incompatible with older versions.
fix
Upgrade to tramway-core-router ^3.3.0 or newer.
affects: <0.5.0
gotchaThe send method's options parameter expects a links array with {label, link, formatted} objects. If formatted is not set to false for relative links, absolute URLs may break.
fix
Pass links with formatted: false for relative paths.
affects: >=0.0.0
gotchaThe HATEAOSAPIProvider decorator requires a pre-configured 'provider.api' from tramway-connection-rest-api. Missing this dependency will cause runtime errors.
fix
Ensure tramway-connection-rest-api is installed and provider.api is registered in DI.
affects: >=0.0.0
deprecatedNo deprecation warnings at this version.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'tramway-core-router'
Missing peer dependency tramway-core-router
fix
Install tramway-core-router: npm install tramway-core-router@^3.3.0
TypeError: Cannot read properties of undefined (reading 'formatEntity')
HATEAOSFormatter service not properly injected into controller
fix
Add hateoas.service.formatter to the controller's constructor dependencies in services config.
Error: Cannot find module 'tramway-connection-rest-api'
Missing dependencies for HATEAOSAPIProvider
fix
Install tramway-connection-rest-api: npm install tramway-connection-rest-api
TypeError: options.links is not iterable
Options passed to send method does not contain a links array
fix
Provide options with links array: this.formatter.send(res, item, { links: [] });
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies
tramway-core-routerrequiredPeer dependency required for routing and HTTP response handling.
Agent activity
31 hits · last 30 days
node
26
Bingbot
1
OpenAI (training)
1
Resources
tramway-formatter-hateaos — npm install tramway-formatter-hateaos · libregistry