A sample script which covers how to use apiwriter ( to generate content for your REST based web api.


There are two folders
- /docs: contains a sample script to generate resources. This is the interesting purpose of this sample.
- /svc: a sample node web api for the docs script to hit. Simply run node app.js to start up the sample svc. This is not interesting - it's just meant to be a sample service to play with the doc generation api.


This simple sets some request options, set some doc options and then tells it to generate docs
by looking in the resources folder and running each script. The recommendation is one script per


A sample script to generate output for the "discussions" resources. This is the most interesting use of the apiwriter.

It creates a context object for state between the calls. This must be exported as getContext.
You then have to export a method called submitRequests.

In the callback, the result is passed back to you so you can update the context and in subsequent
requests, you can reference data from the context like {createdId}.

var apiwriter = require('apiwriter');

exports.getContext = function() {
    return {
        createdId: null

exports.submitRequests = function()
    apiwriter.postJson('/discussions', {"title":"A discussion", "author":"me"},
        function(context, result) {
            context.createdId =;

    apiwriter.postJson('/discussions', {"title":"Another discussion", "author":"me"});
        function(context, result) {
            context.discussionId = result.responseBody[0].id;


Last edited May 20, 2013 at 6:55 PM by bryanmacfarlane, version 2