All Projects → apiaryio → Protagonist

apiaryio / Protagonist

Licence: mit
Protagonist is Node.js wrapper for the API Blueprint parser

Projects that are alternatives of or similar to Protagonist

arcscord
A Discord library written in typescript
Stars: ✭ 18 (-94.75%)
Mutual labels:  nodejs-modules
tracking-number-validation
A simple way to validate tracking number for the following couriers.
Stars: ✭ 22 (-93.59%)
Mutual labels:  nodejs-modules
ghost-storage-cloudinary
🚀 A fully-featured and deeply tested Cloudinary Ghost storage adapter
Stars: ✭ 49 (-85.71%)
Mutual labels:  nodejs-modules
vayder
Easy and concise validations for Express routes
Stars: ✭ 26 (-92.42%)
Mutual labels:  nodejs-modules
draughtsman
API Blueprint Parser for Python 3
Stars: ✭ 22 (-93.59%)
Mutual labels:  api-blueprint
Wedge
可配置的小说下载及电子书生成工具
Stars: ✭ 62 (-81.92%)
Mutual labels:  nodejs-modules
weiboer
基于nodejs 和puppeteer的微博自动发送工具
Stars: ✭ 27 (-92.13%)
Mutual labels:  nodejs-modules
Modclean
Remove unwanted files and directories from your node_modules folder
Stars: ✭ 309 (-9.91%)
Mutual labels:  nodejs-modules
blue bird
API Documentation Generator for the Phoenix Framework
Stars: ✭ 52 (-84.84%)
Mutual labels:  api-blueprint
s3-mongo-backup
Mongodb backups to S3
Stars: ✭ 18 (-94.75%)
Mutual labels:  nodejs-modules
node-opcda
Node.js package to access OPC Da 2.0 for reading and writing. Welcome your PLC JavaScript overlords. Better yet, program them!
Stars: ✭ 30 (-91.25%)
Mutual labels:  nodejs-modules
generate-package-json-webpack-plugin
Generates a package.json file containing the external modules used by your webpack bundle
Stars: ✭ 59 (-82.8%)
Mutual labels:  nodejs-modules
scaling-nodejs
📈 Scaling Node.js on each X, Y and Z axis using Node.js Native Modules, PM2, AWS , Load Balancers, AutoScaling, Nginx, AWS Cloudfront
Stars: ✭ 73 (-78.72%)
Mutual labels:  nodejs-modules
web-ext-deploy
A tool for deploying WebExtensions to multiple stores.
Stars: ✭ 28 (-91.84%)
Mutual labels:  nodejs-modules
Simple Netease Cloud Music
🎵A simple netease music api lib. 简单、统一、轻巧的 Node.js 版网易云音乐 API
Stars: ✭ 268 (-21.87%)
Mutual labels:  nodejs-modules
fastify-axios
Add axios http client to your fastify instance
Stars: ✭ 28 (-91.84%)
Mutual labels:  nodejs-modules
formidable-serverless
Enables use of formidable (node.js module for parsing form data, especially file uploads) in serverless environments.
Stars: ✭ 28 (-91.84%)
Mutual labels:  nodejs-modules
A To Z List Of Useful Node.js Modules
Collection of most awesome node modules that will extend the capability of your node.js application.
Stars: ✭ 315 (-8.16%)
Mutual labels:  nodejs-modules
Drafter
API Blueprint Parser (C++)
Stars: ✭ 286 (-16.62%)
Mutual labels:  api-blueprint
lazy-require
Sponsor this project to keep it maintained, or use Deno instead.
Stars: ✭ 16 (-95.34%)
Mutual labels:  nodejs-modules

logo

Protagonist - API Blueprint Parser for Node.js

AppVeyor

Protagonist is a Node.js wrapper for the Drafter, an API Blueprint parser. API Blueprint is a language for describing web APIs.

Install

NOTE: For general use we recommend that you use the Drafter NPM package instead of Protagonist directly as Protagonist needs to be compiled which may not be possible in every situation.

Protagonist can be installed via the Protagonist npm package by npm or yarn.

$ npm install protagonist
# or
$ yarn install protagonist

Protagonist uses the node-gyp build tool which requires Python 2.7 (3.x is not supported) along with a compiler and other build tools. Take a look at their installation steps for Linux, macOS, and Windows.

Usage

Protagonist offers the ability to both validate, and parse an API Blueprint. It offers the following APIs:

NOTE: It is not recommended to use the synchronous APIs as they can block the Node.JS event loop.

Validating an API Blueprint

You can validate an API Blueprint to determine if the source is a valid document. The parse result will contain any errors or warnings that the document would emit during parsing.

const protagonist = require('protagonist');

const parseResult = await protagonist.parse('# My API');
console.log(JSON.stringify(parseResult, null, 2));

or by using Promises:

const protagonist = require('protagonist');

protagonist.validate('# My API')
  .then((parseResult) => {
    console.log(JSON.stringify(parseResult, null, 2));
  })
  .catch((error) => {
    console.error(error);
  });

See the parse result section below for more information about the structure of the parse result.

Synchronous API

const protagonist = require('protagonist');
const parseResult = protagonist.validateSync('# My API');

Validation Options

Options can be passed to the parser as an optional second argument to both the asynchronous and synchronous interfaces:

const protagonist = require('protagonist');

const options = {
  requireBlueprintName: true,
};
const parseResult = await protagonist.validate('# My API', options);

The available options are:

Name Description
requireBlueprintName Require parsed blueprints have a title (default: false)

Parsing an API Blueprint

You can parse an API Blueprint with async/await:

const protagonist = require('protagonist');

const parseResult = await protagonist.parse('# My API');
console.log(JSON.stringify(parseResult, null, 2));

or by using Promises:

const protagonist = require('protagonist');

protagonist.parse('# My API')
  .then((parseResult) => {
    console.log(JSON.stringify(parseResult, null, 2));
  })
  .catch((error) => {
    console.error(error);
  });

See the parse result section below for more information about the structure of the parse result.

Synchronous API

const parseResult = protagonist.parseSync('# My API');

Parsing Options

Options can be passed to the parser as an optional second argument to both the asynchronous and synchronous interfaces:

const options = {
  generateSourceMap: true,
  generateMessageBody: true,
  generateMessageBodySchema: true,
};
const parseResult = await protagonist.parse('# My API', options);

The available options are:

Name Description
requireBlueprintName Require parsed blueprints have a title (default: false)
generateSourceMap Enable sourcemap generation (default: false)
generateMessageBody Enable generation of messageBody from MSON (default: true)
generateMessageBodySchema Enable generation of messageBodySchema from MSON (default: true)

Parse Result

The format of the parse result is an API Elements structure, there is also API Elements: JS which contains tooling to handle this format in JavaScript. It is recommended to use the provided API Elements tooling to prevent any tight coupling between your tool and a parse result.

As an example, parsing the following API Blueprint:

# GET /
+ Response 204

Would result in the following API Elements Parse Result:

{
  "element": "parseResult",
  "content": [
    {
      "element": "category",
      "meta": {
        "classes": {
          "element": "array",
          "content": [
            {
              "element": "string",
              "content": "api"
            }
          ]
        },
        "title": {
          "element": "string",
          "content": ""
        }
      },
      "content": [
        {
          "element": "resource",
          "meta": {
            "title": {
              "element": "string",
              "content": ""
            }
          },
          "attributes": {
            "href": {
              "element": "string",
              "content": "/"
            }
          },
          "content": [
            {
              "element": "transition",
              "meta": {
                "title": {
                  "element": "string",
                  "content": ""
                }
              },
              "content": [
                {
                  "element": "httpTransaction",
                  "content": [
                    {
                      "element": "httpRequest",
                      "attributes": {
                        "method": {
                          "element": "string",
                          "content": "GET"
                        }
                      },
                      "content": []
                    },
                    {
                      "element": "httpResponse",
                      "attributes": {
                        "statusCode": {
                          "element": "string",
                          "content": "204"
                        }
                      },
                      "content": []
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Developing Protagonist

You can use the following steps to build and test Protagonist.

$ git clone --recursive https://github.com/apiaryio/protagonist.git
$ cd protagonist
$ npm install

While iterating on the package, you can use npm run build to compile Protagonist:

$ npm run build
$ npm test

Protagonist is built using node-gyp, you can consult their documentation for further information on the build system.

License

MIT License. See the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].