{"id":42114,"library":"tramway-formatter-hateaos","title":"Tramway HATEAOS Formatter","description":"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.","status":"active","version":"0.5.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install tramway-formatter-hateaos","lang":"bash","label":"npm"},{"cmd":"yarn add tramway-formatter-hateaos","lang":"bash","label":"yarn"},{"cmd":"pnpm add tramway-formatter-hateaos","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for routing and HTTP response handling.","package":"tramway-core-router","optional":false}],"imports":[{"note":"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.","wrong":"const services = require('tramway-formatter-hateaos').services;","symbol":"services","correct":"import { services } from 'tramway-formatter-hateaos';"},{"note":"Contains HATEAOSAPIProvider, a decorator for APIProvider. Named import for ESM.","wrong":"const { providers } = require('tramway-formatter-hateaos');","symbol":"providers","correct":"import { providers } from 'tramway-formatter-hateaos';"},{"note":"Named export for the HATEAOS entity class. CommonJS require also works.","wrong":"","symbol":"HATEAOSEntity","correct":"import { HATEAOSEntity } from 'tramway-formatter-hateaos';"},{"note":"Named export for the HATEAOS collection class.","wrong":"","symbol":"HATEAOSCollection","correct":"import { HATEAOSCollection } from 'tramway-formatter-hateaos';"}],"quickstart":{"code":"// Assuming ESM environment with tramway-core-router set up\nimport { services } from 'tramway-formatter-hateaos';\n\n// Use services object to register DI in your config/services/index.js\n// Then access HATEAOSFormatter in a controller:\n// this.formatter.formatEntity(entity);\n// this.formatter.formatCollection(collection);\n// this.formatter.send(res, formattedItem, options);\n\n// For paginated variant, use 'hateoas.service.formatter:paginated' in DI.\n\n// To use HATEAOSAPIProvider:\nimport { providers } from 'tramway-formatter-hateaos';\nconst { HATEAOSAPIProvider } = providers;\n\n// Register in DI:\n// \"provider.hateaos\": {\n//     \"class\": HATEAOSAPIProvider,\n//     \"constructor\": [\n//         {\"type\": \"service\", \"key\": \"provider.api\"},\n//         {\"type\": \"service\", \"key\": \"factory.hateaos\"},\n//         {\"type\": \"parameter\", \"key\": \"api_resource\"}\n//     ]\n// }","lang":"javascript","description":"Demonstrates how to import and register the Tramway HATEAOS Formatter services and providers in a dependency injection container for REST API formatting."},"warnings":[{"fix":"Upgrade to tramway-core-router ^3.3.0 or newer.","message":"Requires tramway-core-router version ^3.3.0. Incompatible with older versions.","severity":"breaking","affected_versions":"<0.5.0"},{"fix":"Pass links with formatted: false for relative paths.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure tramway-connection-rest-api is installed and provider.api is registered in DI.","message":"The HATEAOSAPIProvider decorator requires a pre-configured 'provider.api' from tramway-connection-rest-api. Missing this dependency will cause runtime errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"","message":"No deprecation warnings at this version.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'3.3.0':43 'api':15 'apiprovid':47 'automat':49 'collection/entity':55 'content':29 'content-typ':28 'convert':50 'core':41 'creat':12 'decor':45 'differ':27 'formatt':3,6 'framework':10 'hal/hateaos-compliant':13 'handl':26 'hateao':2,51 'hateaosformatt':20 'header':31 'includ':18 'javascript':57 'mimetyperesolv':24 'object':56 'pagin':34,37 'provid':44 'request':22 'requir':38 'respons':5,52 'rest':14 'router':42 'standard':54 'tramway':1,9,40 'tramway-core-rout':39 'type':30 'v0.5.0':16 'variant':35","created_at":"2026-06-04T18:55:41.097689+00:00","updated_at":"2026-06-04T18:55:41.097689+00:00","problems":[{"fix":"Install tramway-core-router: npm install tramway-core-router@^3.3.0","cause":"Missing peer dependency tramway-core-router","error":"Error: Cannot find module 'tramway-core-router'"},{"fix":"Add hateoas.service.formatter to the controller's constructor dependencies in services config.","cause":"HATEAOSFormatter service not properly injected into controller","error":"TypeError: Cannot read properties of undefined (reading 'formatEntity')"},{"fix":"Install tramway-connection-rest-api: npm install tramway-connection-rest-api","cause":"Missing dependencies for HATEAOSAPIProvider","error":"Error: Cannot find module 'tramway-connection-rest-api'"},{"fix":"Provide options with links array: this.formatter.send(res, item, { links: [] });","cause":"Options passed to send method does not contain a links array","error":"TypeError: options.links is not iterable"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://gitlab.com/tramwayjs/tramway-formatter-hateaos#readme","github":null,"docs":null,"changelog":null,"pypi":null,"npm":"tramway-formatter-hateaos","openapi_spec":null,"status_page":null,"smithery":null,"categories":["api"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}