Fury.js
API Description SDK
Wardaddy: Best job I ever had.
Fury provides uniform interface to API description formats such as API Blueprint.
Usage
Install
Fury.js is available as npm module.
Install globally:
$ npm install -g fury
or as a dependency:
$ npm install --save fury
Refract Interface
Fury.js offers an interface based on the Refract Project element specification and makes use of the API description and data structure namespaces. Adapters convert from formats such as API Blueprint into Refract elements and Fury.js exposes these with API-related convenience functionality. For example:
;const source = '# My API\n...'; fury;
Once you have a parsed API it is easy to traverse:
apiresourceGroups;
It is also possible to do complex document-wide searching and filtering. For example, to print out a listing of HTTP methods and paths for all defined example requests:
/* * Prints out something like: * * POST /frobs * GET /frobs * GET /frobs/{id} * PUT /frobs/{id} * DELETE /frobs/{id} */{ if itemelement === 'httpRequest' && itemstatusCode === 200 return true; return false;} console; api;
Multiple Fury Instances
There may come a day when you need to have multiple Fury instances with different adapters or other options set up in the same program. This is possible via the Fury
class:
; const fury1 = ;const fury2 = ; fury1;
Writing an Adapter
Adapters convert from an input format such as API Blueprint into refract elements. This allows a single, consistent interface to be used to interact with multiple input API description formats. Writing your own adapter allows you to add support for new input formats.
Adapters are made up of a name, a list of media types, and three public functions: detect
, parse
, and an optional serialize
. A simple example might look like this:
const name = 'my-adapter';const mediaTypes = 'text/vnd.my-adapter'; { // If no media type is know, then we fall back to auto-detection. Here you // can check the source and see if you think you can parse it. return source !== null;} { // Here you convert the source into refract elements. Use the `minim` // variable to access refract element classes. const Resource = minim; // ... ;} { // Here you convert `api` from javascript element objects to the serialized // source format. // ... ;} name mediaTypes detect parse serialize;
Now you can register your adapter with Fury.js:
;; // Register my custom adapterfury; // Now parse my custom input format!fury;
Legacy Interface
This is the older "legacy" interface for API Blueprint and Apiary Blueprint parsing.
API Blueprint Parsing
var parser = legacyBlueprintParser;var source = '# My API\n'; parser;
Markdown Rendering
The legacy interface also offers access to Markdown rendered as used internally by API and Apiary Blueprint parsers.
var markdownRenderer = legacyMarkdownRenderer;var source = '# My API\n'; markdownRenderer;
Development
Building & Testing
Parts of Fury.js are written in Coffeescript, so you must build the final library before it can be used. All of the build/test/etc commands are run through npm:
# Build the library npm run compile # Run the unit and integration tests npm test # Generate a coverage report npm run coverage # Open the HTML report open coverage/lcov-report/index.html