@useoptic/document-node-http

0.1.6 • Public • Published

Optic for micro

Optic's documenting middleware for micro or any other framework that uses the node http primitives. This package supports APIs written in Javascript, Typescript, or ReasonML and can be used with the testing framework of your choice.

Usage

Install as a dev dependency

npm install @useoptic/document-node-http --save-dev

Before testing your micro service, wrap it in the documenting middleware.

import {withOptic} from '@useoptic/document-node-http/micro'

const micro = require('micro')
const test = require('ava')
const listen = require('test-listen')
const request = require('request-promise')

const microWithOptic = withOptic(micro);

test('my endpoint', async t => {
  const service = microWithOptic(async (req, res) => {
    micro.send(res, 200, {
      test: 'woot'
    })
  })

  const url = await listen(service)
  const body = await request(url)

  t.deepEqual(JSON.parse(body).test, 'woot')
  service.close()
})

Next Steps

Once you've setup the documenting middleware, review the Optic docs to finish setting up Optic for your API

Dependents (0)

Package Sidebar

Install

npm i @useoptic/document-node-http

Weekly Downloads

1

Version

0.1.6

License

ISC

Unpacked Size

19.2 kB

Total Files

12

Last publish

Collaborators

  • niclim
  • acunniffe
  • opticbot
  • notnmeyer