Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Developers

Z edited this page Dec 4, 2015 · 8 revisions

Developing tools for API Blueprint

NOTE: This article is outdated, proceed with care.

It is best to consume the API Blueprint AST directly either via a binding interface or the native parser interface.

Alternatively, you can use the parser command line tool and then process its output AST media type.

Using a parser binding (Node.js)

  1. Install binding for your language (e.g. Protagonist for Node.js)

    $ npm install protagonist
  2. Parse your API Blueprint into its AST

    var protagonist = require('protagonist');
    
    var blueprint = '''
    # GET /message
    + Response 200 (text/plain)
    
            Hello World!
    ''';
    
    protagonist.parse(blueprint, function(err, result) {
    
        ...
    });

Using the command line tool

  1. Get Snow Crash command line tool

    $ brew install --HEAD \
        https://raw.github.com/apiaryio/snowcrash/master/tools/homebrew/snowcrash.rb

    Build notes for Linux and Windows.

  2. Parse API Blueprint into its AST media type

    $ cat << 'EOF' | snowcrash --format json
    # GET /message
    + Response 200 (text/plain)
    
            Hello World!
    EOF
    {
      "_version": "1.0",
      "metadata": {},
      "name": "",
      "description": "",
     
     ...

Using the native parser interface (C/C++)

  1. Build Snow Crash

    $ ./configure
    $ make

    See full build instructions

  2. Parse your API Blueprint into its AST

    #include "snowcrash.h"
    
    snowcrash::SourceData blueprint = R"(
    # GET /message
    + Response 200 (text/plain)
    
            Hello World!
    )";
    snowcrash::Result result;
    snowcrash::Blueprint ast;
    
    snowcrash::parse(blueprint, 0, result, ast);
    
    ...
Clone this wiki locally