@dxc-technology/halstack-client

中文文档
1.6.8发布于 2026/09/18Apache v2.0ESM + CJS近 30 天下载 4699

DXC Technology Halstack Client

原始使用文档
文档目录11 节
  1. Installation
  2. Use in Node.js
  3. Use in browsers
  4. HalResource Factory
  5. HalResource Object
  6. HalInteraction Object
  7. HalProperty Object
  8. HalResponse Factory
  9. HalResponse Object
  10. HalApiCaller Module
  11. To Do

Halstack Client for JavaScript

Halstack Client for JavaScript enables developers to easily work with hypermedia-based APIs in a declarative manner. It offers a set of functionalities to facilitate the navigation between hypermedia resources and get access to their properties dynamically, based on the HAL and JSON Hyper-Schema draft specifications, as well as DXC API guidelines and HAL extensions.

This SDK is released as a client-agnostic library that can be used both in browser applications (such as Vanilla JS, React or Angular applications) or backend applications (NodeJS applications). As such, it is distributed as UMD.

Installation

npm install @dxc-technology/halstack-client

Use in Node.js

// require from the dependency the modules you need
const {
  HalResource,
  HalResponse,
  HalApiCaller,
} = require("@dxc-technology/halstack-client");

Use in browsers

// require from the dependency the modules you need
import {
  HalResource,
  HalResponse,
  HalApiCaller,
} from "@dxc-technology/halstack-client";

HalResource Factory

The purpose of this module is facilitating the access to the information of a given resource. This factory function receives a JSON object with the HAL Resource Representation as a parameter.

It returns a HalResource Object, encapsulating the original HAL Resource Representation and including a set of functions that will allow you to access the data from the resource in a declarative manner, without having to fully understand the details of how HAL resource representation is structured.

The HalResource can also be used to help developers to create a compliant HalResource representation to be included in a Hal response, exposing functions to add different sections that typically can be found in a resource.

HalResource Object

NameTypeDescription
resourceRepresentationObjectThe whole resource representation.
getTitle()=>StringReturns the resource title. Taken from \_options.title.
getInteractions()=>HalInteraction[]Returns an array of HalInteraction objects. Taken from the \_options.links array.
getInteraction(String)=>HalInteractionReceives a string with the rel of the interaction. Returns the HalInteraction object.
getItems()=>Object[]Returns an array of the original item link objects. Taken from the \_links.item array.
getItem(Number)=>ObjectReceives the index of the item. Returns the item object.
getLinks()=>Object[]Returns an array of the original link objects (adding the rel), ignoring item link. Taken from the \_links object.
getLink(String)=>ObjectReceives a string with the rel of the link. Returns the link object (adding the rel).
getProperties()=>Object[]Returns an array of HalProperty objects. Taken from the resource root level properties.
getProperty(String)=>ObjectReceives a string with the key of the property. Returns the HalProperty object.
getRequiredProperties()=>String[]Returns an array with the required properties key. Taken from the \_options.required array.
isPropertyRequired(String)=>BoolReceives the key of a property. Returns true if it exists within the \_options.required array.
getSchemaProperties()=>Object[]Returns an array of the original schema objects for properties (adding key). Taken from the \_options.properties object.
getSchemaProperty(String)=>ObjectReceives the key of a property. Returns the property's schema object (adding key) if exists within \_options.properties object.
addLink(Object)=>voidReceives an object as parameter. This object can contain the usual link properties as { rel, name, href, title } where rel and href are required. The object will be added to the \links section using rel as key
addLinks(Object)=>voidReceives an object as parameter. This object can contain the usual link properties as { rel, name, href, title } where rel and href are required. The object will be added to the \links section using rel as key
addTitle(String)=>voidAssign the parameter received to the resource title in \_options.title
addItem(Object)=>voidAdd the object received as parameter as a resource \_link item
addItems(Object[])=>voidAdd every object in the list received as parameter as a resource \_link item.
addProperties(Object)=>voidAdd the key:values found in the object received as parameter as resource properties.
addOptionsProperties(Object)=>voidAdd every property received in parameter as property under the \_options.properties section
addOptionsProperty(Object)=>voidAdd the property ({key: schema}) received in parameter as property under the \_options.properties section
addInteraction(Object)=>voidAdd the object received as parameter ({rel: Interaction}) under the options.link section
addOptions(Object)=>voidIt receives an object as parameter and add interactions , properties, required and title if those sections are found as object keys.

HalInteraction Object

Includes the existing attributes of the original interaction object. It provides the following additional helper functions:

NameTypeDescription
getRequiredProperties()=>String[]Returns an array with the required properties key. Taken from the "schema.required" array of the interaction.
isPropertyRequired(String)=>BoolReceives the key of a property. Returns true if it exists within the "schema.required" array of the interaction.
getSchemaProperties()=>Object[]Returns an array of the original schema objects for properties (adding key). Taken from the \schema.properties object of the interaction.
getSchemaProperty(String)=>ObjectReceives the key of a property. Returns the property's schema object (adding key) if exists within \schema.properties object of the interaction.
hasProperty(String)=>BoolReceives the key of a property. Returns true if it exists within the \schema.properties object of the interaction.

HalProperty Object

NameTypeDescription
isRequired()=>BoolReturns true if the property exists within the \_options.required array.
existsInInteraction(String)=>BoolReceives a string with the rel of an interaction. Returns true if the property exists within the "schema.properties" object of the interaction.
getSchema()=>ObjectReturns the property's schema object (adding key) if exists within \_options.properties object.

HalResponse Factory

The purpose of this module is facilitating the access to the information returned inside an API response. This factory function accepts an object with the following attributes as a parameter:

NameTypeDescription
bodyObjectThe message-body is the data bytes transmitted associated with a http response.
headersObjectContains the http headers which provide information about the server and about further access to the resource identified by the Request-URI.
statusNumberStatus codes are issued by a server in response to a client's request made to the server. It includes codes from IETF Request for Comments (RFCs).

It returns HalResponse Object.

HalResponse Object

NameTypeDescription
bodyJSON ObjectResponse message-body
headersJSON ObjectHttp headers
statusNumberHttps response code
typeStringResponse format. Example: application/JSON
halResourceHalResourceHalResource Object composed using the information provided inside the body.
containsHalResourceBoolTrue if the content of the response is a HAL resource.

HalApiCaller Module

This module is a HTTP client which takes care of handing out parsed HalResponses. It exports the following functions:

NameTypeDescription
setGlobalHeadersfunctionReceives a headers object that will be used for all http requests done with this module.
getfunction:Promise(HalResponse)Receives a { url, headers } object as a parameter. Returns a promise and will pass a HalResponse object to the handler.
optionsfunction:Promise(HalResponse)Receives a { url, headers } object as a parameter. Returns a promise and will pass a HalResponse object to the handler.
patchfunction:Promise(HalResponse)Receives a { url, body, headers } object as a parameter. Returns a promise and will pass a HalResponse object to the handler.
postfunction:Promise(HalResponse)Receives a { url, body, headers } object as a parameter. Returns a promise and will pass a HalResponse object to the handler.
putfunction:Promise(HalResponse)Receives a { url, body, headers } object as a parameter. Returns a promise and will pass a HalResponse object to the handler.
delfunction:Promise(HalResponse)Receives a { url, headers } object as a parameter. Returns a promise and will pass a HalResponse object to the handler.

License

See Halstack Client License here

To Do

See our issues

版本与发布记录

@dxc-technology/halstack-client 共发布 209 个版本,首次发布于 2019/06/26;过去 12 个月发布了 19 个版本。

版本发布日期距今
1.6.8latest2026/09/181 个月前
0.0.0-73635e6next2026/09/161 个月前
1.6.72026/09/102 个月前
0.0.0-5e7dbf22026/09/092 个月前
0.0.0-b22d3432026/09/042 个月前
0.0.0-b1cb3bb2026/09/042 个月前

其他发布通道:beta → 1.1.3-beta.12,alpha → 1.1.5-alpha.20200707.1,next → 0.0.0-73635e6。

关于 @dxc-technology/halstack-client 的常见问题

@dxc-technology/halstack-client 是什么?

DXC Technology Halstack Client

如何安装 @dxc-technology/halstack-client?

在项目目录运行 npm install @dxc-technology/halstack-client,或使用 pnpm add / yarn add / bun add。

@dxc-technology/halstack-client 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dxc-technology__halstack-client 是否存在。

@dxc-technology/halstack-client 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dxc-technology/halstack-client 可以商用吗?

@dxc-technology/halstack-client 使用 Apache v2.0 许可。声明的许可为 Apache v2.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@dxc-technology/halstack-client 的下载量有多少?

根据 npm 官方下载统计,@dxc-technology/halstack-client 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,699 次,日均约 157 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dxc-technology/halstack-client 还在维护吗?

最新版本 1.6.8 发布于 2026/09/18(1 个月前);至今共发布 209 个版本,其中过去 12 个月发布了 19 个;首次发布于 2019/06/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。