You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

apimd

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apimd

Write APIs in Markdown and use them as mocks.

0.2.1
Source
npmnpm
Version published
Weekly downloads
2
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

apimd

npm version build status issue tracker

apimd lets you to write APIs in Markdown and use them as mocks.

## GET /api/site

```yaml
branding:
  label: "My Site"
  url: "/mysite.svg"
navigation:
  label: "My Site"
  items:
  - label: "Home"
    url: "/"
  - label: "Accounts"
    url: "/accounts"
  - label: "About"
    url: "/about"
```

A GET request to /api/site will return the following json:

{
  "branding": {
    "label": "My Site",
    "imageURL": "/mysite.svg"
  },
  "navigation": {
    "label": "My Site",
    "items": [
      {
        "label": "Home",
        "url": "/"
      },
      {
        "label": "Accounts",
        "url": "/accounts"
      },
      {
        "label": "About",
        "url": "/about"
      }
    ]
  }
}

APIs written in Markdown can specify multiple endpoints in the same file:

## GET /api/one

```yaml
payload: "one"
```

## GET /api/two

```yaml
payload: "two"
```

APIs written in Markdown can also qualify endpoints with requests.

## POST /api/login

### Request

```yaml
username: "test"
password: "test"
```

### Response

```yaml
givenName: "Test"
sessionId: 1138
```

A POST request to /api/login will return a 401 with the following json:

{}

However, a POST request with a body of {"username":"test","password":"test"} will return a 200 with the following json:

{
  "givenName": "Test",
  "sessionId": 1138
}

APIs written in Markdown can qualify requests by headers as well.

## POST /api/isLoggedIn

### Request Headers

```yaml
x-session-id: "1138"
```

### Response

```yaml
success: true
```

A POST request with a x-session-id header of 1138 will return a 200 with the following json:

{
  "success": true
}

Installation

npm install apimd

Usage with Markdown

const parse = require('apimd/parse')

parse(MARKDOWN_STRING)

Usage with Express

// server.js
const express = require('express')
const apimd = require('apimd/middleware')

app.use(apimd(/* options */))

Usage with Rescripts

// .rescriptsrc.js
module.exports = [
  ['apimd/rescript']
]

Usage with Create React App Rewired

// config-overrides.js
const apimd = require('apimd/rewired')

module.exports = apimd(module.exports, /* options */)

Options

The following fields may be configured:

{
  "fallbackBody": {},
  "fallbackHeaders": {},
  "fallbackStatus": 401,
  "jsonReplacer": null,
  "jsonSpace": "  ",
  "live": false,
  "src": "api.md"
}

Note: In the rescript and rewired versions, src is src/api.md.

Configuration with package.json

The rescript and rewired versions of apimd may be configured from package.json:

{
  "apimd": {
    "live": true
  }
}

FAQs

Package last updated on 15 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts