This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Developers
Kyle Fuller edited this page Dec 16, 2015
·
8 revisions
It is best to consume the API Blueprint directly either via a binding interface, the native parser interface or the API Blueprint parsing service.
Alternatively, you can use the parser command line tool and then process its output Refract API Description.
-
Install binding for your language (e.g. Protagonist for Node.js)
$ npm install protagonist
-
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(error, result) { ... });
-
Get Drafter command line tool
$ brew install --HEAD \ https://raw.github.com/apiaryio/drafter/master/tools/homebrew/drafter.rb
-
Parse API Blueprint into the Refract API Description namespace:
$ cat << 'EOF' | drafter --format json # GET /message + Response 200 (text/plain) Hello World! EOF { "element": "parseResult", "content": [ { "element": "category", ...
-
Build Drafter
$ ./configure $ make
See full build instructions
-
Parse your API Blueprint into its AST
#include "drafter.h" // Blueprint Parser #include "SerializeResult.h" // Result Wrapper for serialization #include "sosJSON.h" // Serializer mdp::ByteBuffer blueprint = R"( # My API ## GET /message + Response 200 (text/plain) Hello World! )"; // Blueprint parsing snowcrash::ParseResult<snowcrash::Blueprint> ast; drafter::ParseBlueprint(blueprint, 0, ast); std::cout << "API Name: " << ast.node.name << std::endl; // Serialization to JSON format sos::SerializeJSON serializer; serializer.process(drafter::WrapResult(ast.node, drafter::WrapperOptions(drafter::RefractASTType)), std::cout);
$ curl -X POST '
--header "Content-Type: text/vnd.apiblueprint" \
--header "Accept: application/vnd.refract.parse-result+json" \
--data-binary "# My API Blueprint" \
https://api.apiblueprint.org/parser
{"element":"parseResult","content":[{"element":"category","meta":{"classes":["api"],"title":"My API Blueprint"},"content":[]}]}
Full API documentation for the API Blueprint parsing service can be found at Apiary.