0.0.2 • Published 3 years ago

curldoc v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

curldoc

curldoc is a simple executable Web API document format using the curl command.

The CLI Application of curldoc behave a HTTP mock server from a markdown file of Web API document.

You can create a mock server with such as the following markdown document.

Usage

CLI

# Install CLI-app
$ npm install --global curldoc

# Download sample document
$ curl -sL https://raw.githubusercontent.com/yammerjp/curldoc/main/example/helloworld.md > helloworld.md

# Start mock server
$ curldoc helloworld.md

# Usage:
# $ curldoc (--port <TCP port>) <markdown file paths ... >

Library

  1. Install the npm package 'curldoc' with npm i curldoc for your project
  2. Create API document (example)
  3. Write TypeScript/JavaScript such as the following code
import curldoc from 'curldoc'

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

async function main() {
  const server = await curldoc.server(3000, [ 'path/to/markdown/file.md' ])

  await wait(1000)

  server.close()
  console.log('closed')
}

main()

Support curl options

You can use following the options in a markdown's codeblock 'curldoc-request'.

  • --header, -H ... specify http request headers
  • --data-raw ... specify a http request body
  • --request, -X ... specify a http request method

If you want to use other options, please contribute to the repository. (curl options are processed in /src/documentProcessor/curlOptionHandlers.ts)

LICENSE

MIT