npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xapi-js/adaptor-express

v1.8.0

Published

Express.js adaptor for X-API.

Downloads

308

Readme

@xapi-js/adaptor-express

Express용 X-API middleware입니다. operation schema를 전달하면 handler는 타입이 추론된 plain object를 받고 반환합니다.

기본 codec은 Nexacro XML이며, codec을 지정하지 않은 기존 middleware 동작은 그대로 유지됩니다.

설치

pnpm add @xapi-js/core @xapi-js/adaptor-express express

기본 XML 사용

import express from "express";
import { xapi } from "@xapi-js/core";
import { xapiExpress } from "@xapi-js/adaptor-express";

const operation = xapi.operation({
  request: xapi.root({
    datasets: { input: xapi.dataset({ id: xapi.int() }) },
  }),
  response: xapi.root({
    datasets: { output: xapi.dataset({ id: xapi.int(), name: xapi.string() }) },
  }),
});

const app = express();
app.use(express.text({ type: "application/xml" }));
app.post("/xapi", xapiExpress(operation, request => ({
  parameters: {},
  datasets: {
    output: request.datasets.input.map(({ id }) => ({ id, name: `user-${id}` })),
  },
})));

codec을 생략하면 application/xml이 아닌 요청은 next()로 전달됩니다.

operation codec

const operation = xapi.operation({
  codec: {
    profile: "nexacro-json-1.0",
    options: { zlib: true },
  },
  request: xapi.root({
    datasets: { input: xapi.dataset({ id: xapi.int() }) },
  }),
  response: xapi.root({
    datasets: { output: xapi.dataset({ id: xapi.int() }) },
  }),
});

const app = express();
app.use(express.raw({
  type: ["application/json", "application/x-ssv", "application/octet-stream"],
}));
app.post("/xapi", xapiExpress(operation, request => ({
  parameters: {},
  datasets: { output: request.datasets.input },
})));

Binary와 zlib transport를 처리하려면 express.raw()를 사용해 body를 Buffer로 유지해야 합니다. BufferUint8Array로 처리됩니다. JSON·SSV도 raw bytes로 유지하면 codec별 처리 경로가 동일합니다.

어댑터 옵션으로 codec 선택

operation을 수정하지 않고 middleware에 codec을 지정할 수 있습니다.

app.post("/xapi", xapiExpress(operationWithoutCodec, handler, {
  codec: {
    profile: "xplatform-binary-5000",
    options: { zlib: true },
  },
}));

operation의 codec이 있으면 adapter option보다 우선합니다. codec 객체에는 다음 필드를 지정할 수 있습니다.

  • profile: WireProfile
  • options: WireCodecOptions (zlib, strict, limits 등)
  • contentType: 기본 media type을 서버 계약에 맞게 재정의

기본 media type은 XML application/xml, JSON application/json, SSV application/x-ssv, Binary application/octet-stream입니다.

Raw XapiRoot handler

app.post("/xapi", xapiExpress(async root => {
  return root;
}, { codec: "nexacro-ssv" }));

raw handler에서도 codec을 지정하면 handler 전후의 XapiRoot와 wire body 변환은 middleware가 처리합니다.