apimd lets you to write APIs in Markdown and use them as mocks.
## GET /api/site White label site branding and navigation? I have a bad feeling about this. ```yamlbranding: title: "Fortune Wookie" imageUrl: "/logo.svg"navigation: title: "Site" items: - title: "Home" pageUrl: "/" - title: "Darth Later" pageUrl: "/going-out" - title: "Ellie Vader" pageUrl: "/going-up"``` ## POST /api/login ### Request It's an older login, server, but it checks out. ```yamlusername: "han@benslightsaber.ouch"password: "j0nes"``` ### Response We're fine. We're all fine here, now, thank you. ```yamltoken: "THX1138"user:- givenName: "Indiana"- familyName: "Solo"``` ### Response 401 I find your lack of authentication disturbing. ```yamlerror: "Missing {username,password} request body"``` ## GET /api/is-logged-in ### Request Headers ```yamlx-session-id: "THX1138"``` ### Response Body Do... ```yamlsuccess: true``` ### Response Body Or do not... ```yamlsuccess: false```
Based on the example, a GET
request to /api/site
returns the following json:
A POST
request to /api/login
returns the following 401
json:
However, adding a request body of {"username":"han@benslightsaber.ouch","password":"j0nes"}
returns the following json:
Also, a POST
request to /api/is-logged-in
returns the following json:
While adding a x-session-id
header of THX1138
returns the following json:
It is neat how JSON and YAML formats are supported, and JavaScript as well:
'https://api.openbrewerydb.org/breweries' type: 'json'
Have fun!
Installation
npm install apimd
Usage with Markdown
const parse =
Usage with Express
// server.jsconst express = const apimd = app
Usage with Rescripts
// .rescriptsrc.jsmoduleexports = 'apimd/rescript'
Usage with Create React App Rewired
Add apimd to config-overrides.js
in your React app directory:
// config-overrides.jsconst apimd = moduleexports = devServer:
Options
The following default options may be configured:
Note: In the rescript and rewired versions, src
is "src/api.md"
and live
is true
.
Configuration with package.json
The rescript and rewired versions of apimd may also be configured from package.json
: