HTTP Request/Response to API Blueprint Formatter
The `api-blueprint-http-formatter` package is a JavaScript utility designed to transform structured HTTP request and response objects into a string formatted according to the API Blueprint specification. It takes a JavaScript object containing `request` and `response` keys, adhering to the data model typically used by the Gavel validation tool, and outputs a textual representation suitable for API Blueprint documentation. The current and only released version is 0.0.1. This project appears to be abandoned, with its last commit on GitHub dating back to 2014, and is no longer actively maintained. The broader API Blueprint ecosystem has seen a general decline in new tooling and adoption, with the industry largely shifting towards OpenAPI/Swagger for API description, partly due to the shutdown of major platforms like Apiary.io which championed API Blueprint. This package focuses exclusively on formatting and does not offer parsing, validation, or other API Blueprint-related functionalities.
Common errors
-
TypeError: bf.format is not a function
cause This typically occurs if the module was `require`d incorrectly, or if the path to the formatter was wrong, leading to `bf` not being the expected module object with a `format` method.fixEnsure you are using `const bf = require('api-blueprint-http-formatter');` and then calling `bf.format(post);`. If requiring from a local file, ensure the path `require('./src/api-blueprint-http-formatter')` is correct relative to your script. -
Error: Cannot find module 'api-blueprint-http-formatter'
cause The package is not installed or not resolvable by Node.js.fixInstall the package using npm: `npm install api-blueprint-http-formatter` or ensure it's listed in your `package.json` dependencies and `npm install` has been run.
Warnings
- breaking This package is fundamentally unmaintained, with its last commit in 2014 and a 0.0.1 version. It is unlikely to receive updates for security vulnerabilities, bug fixes, or compatibility with newer Node.js versions or API Blueprint specification changes.
- gotcha The API Blueprint specification, while once popular, has largely been superseded by OpenAPI/Swagger. Many modern API design and documentation tools, including Apiary.io (a former champion of API Blueprint), have either shut down or shifted focus, making API Blueprint a less supported standard.
- gotcha This package is a CommonJS module and does not natively support ES module (`import`) syntax. Attempting to `import` it directly in an ESM context will result in an error unless a transpilation step or a CommonJS compatibility loader is used.
- gotcha The package expects input objects to conform to the HTTP request and response data models used by the Gavel validation tool. Deviations from this precise structure may lead to malformed or incorrect API Blueprint output.
Install
-
npm install api-blueprint-http-formatter -
yarn add api-blueprint-http-formatter -
pnpm add api-blueprint-http-formatter
Imports
- format
import { format } from 'api-blueprint-http-formatter';const formatter = require('api-blueprint-http-formatter').format; - default export
import bf from 'api-blueprint-http-formatter';
const bf = require('api-blueprint-http-formatter'); const blueprint = bf.format(post); - * as formatter
import * as formatterModule from 'api-blueprint-http-formatter';
const formatterModule = require('api-blueprint-http-formatter');
Quickstart
const bf = require('api-blueprint-http-formatter');
const httpPair = {
"request": {
"method": "POST",
"uri": "/shopping-cart",
"headers": {
"User-Agent": "curl/7.24.0",
"Host": "api.example.com",
"Accept": "*/*",
"Content-Type": "application/json",
"Content-Length": "39"
},
"body": "{ \"product\":\"1AB23ORM\", \"quantity\": 2 }"
},
"response": {
"statusCode": "201",
"statusMessage": "Created",
"headers": {
"Content-Type": "application/json",
"Date": "Sun, 21 Jul 2009 14:51:09 GMT",
"X-Apiary-Ratelimit-Limit": "120",
"Content-Length": "50"
},
"body": "{ \"status\": \"created\", \"url\": \"/shopping-cart/2\" }"
}
};
const blueprintOutput = bf.format(httpPair);
console.log(blueprintOutput);