0.0.3 • Published 6 years ago

remark-examples v0.0.3

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

remark-examples

NPM Travis CI MIT License

A remark plugin that dynamically populates local or remote RESTful API examples from links.

Installation

$ npm install remark-examples

Usage

This plugin is to be used with remark, e.g.

import Remark from 'remark';
import RemarkExamples from 'remark-examples';

Remark()
  .use(
    RemarkExamples({
      fetcher: filePath => {
        return get(
          `api/documentation/file?path=${encodeURIComponent(filePath)}`
        ).then(({ data }) => {
          if (data) {
            return JSON.stringify(data, null, 2);
          }
          return undefined;
        });
      },
      baseUrl: 'https://api.grhodes.io'
    })
  )
  .process(markdown, function (err, file) {
    if (err) throw err;

    console.log(String(file));
  });

This plugin does a conversion when the markdown file contains lines starting with #doc:

#doc:json:example shipping-notifications/post/:organization/shipping-notifications/simple

The above will be converted to code:

```
curl -X POST -d @body.json -u <api-token>: https://api.grhodes.io/:organization/shipping-notifications
```

body.json

```
{ example: 'example body json' }
```

API Response

```
{ example: 'example body' }
```