No description
  • JavaScript 91.9%
  • Makefile 8.1%
Find a file
suresh-hashicorp 971987fbb4
Merge pull request #34 from hashicorp/suresh/fix-vuln
Upgrade vulnerable packages
2026-04-02 12:10:28 +05:30
.github Merge pull request #22 from hashicorp/add-code-owners-file 2025-12-16 12:28:19 +05:30
bin Reduce dependencies and consolidate functionality slightly 2019-06-10 11:37:57 +00:00
lib Package upgrades (#8) 2021-06-29 17:10:40 +01:00
location Prettier 2018-07-02 13:55:40 +01:00
reader Prettier 2018-07-02 13:55:40 +01:00
vars Include HTTP body in the vars object 2020-01-06 15:31:10 +00:00
.gitignore Move to hashicorp org 2018-06-01 15:24:04 +01:00
.npmignore Prettier 2018-07-02 13:55:40 +01:00
index.d.ts Start using typedoc and add a minimal public api doc 2019-06-12 10:39:05 +00:00
index.js Return the unJSONed content if we can't encode it 2020-01-20 11:51:34 +00:00
LICENSE [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:57 +00:00
Makefile Start using typedoc and add a minimal public api doc 2019-06-12 10:39:05 +00:00
package-lock.json Merge branch 'master' into suresh/fix-vuln 2026-04-02 12:06:28 +05:30
package.json Package upgrades (#8) 2021-06-29 17:10:40 +01:00
README.md Include HTTP body in the vars object 2020-01-06 15:31:10 +00:00

api-double

api-double serving via HTTP or other means

See https://github.com/hashicorp/consul-api-double/ for an example of an api-double.

'Templates' use simple native javascript template literals for very basic looping and basic logic for providing fake data.

Usage

CLI/Server

api-double --dir path/to/templates

# Flags

--dir : set the path to template files (default ./)
--seed : set the seed for faker to use
--port : set the port to serve from (default: 3000)

# ENV vars

HC_API_DOUBLE_PORT : default port to use
HC_API_DOUBLE_DIR : default path to use
HC_API_DOUBLE_SEED: default seed to use

Browser/frontend only usage

TODO

Wildcard templates

To provide a double for /v1/health/service/:name

Create a /v1/health/service/_ template file. This will be used for /v1/health/service/*. Within the template the * will be in location.segment(3)

Further configuration will be provided by a /v1/health/service/.config file or similar as and when needed.

Extra template helpers:

Right now very subject to change. But the idea is to keep them as minimal as possible and just rely on faker, plus helpers to get things you need for doing stuff like this (easy way to loop, access to url params and headers)

HTTP properties

HTTP data is accessible via the http object using the following properties:

http.method
http.headers.*
http.body.*
http.cookies.*

env(key, defaultValue)

Gets the 'environment' value specified by key, if it doesn't exist, use the default value. 'environment' variables come from cookies by default, which can be easily set using the browsers Web Inspector

range(int)

Simple range function for creating loops

[
    ${
        range(100000).map(
            item => {
                return `"service-${item}"`;
            }
        );
    }
]
// yields
[
    "service-1",
    ...,
    "service-100000"
]

fake

Object containing access to various faker functions

[
    ${
        range(100000).map(
            item => {
                return `${fake.address.countryCode().toLowerCase()-${item}}`;
            }
        );
    }
]
// yields
[
    "it-1",
    ...,
    "de-100000"
]

location.pathname

Reference to the current url

// /v1/catalog/datacenters
[
    "${location.pathname}"
]
// yields
[
    "/v1/catalog/datacenters"
]

This gives you a place to access queryParams location.search.queryParamName

location.pathname.get(int)

Reference a 'segment' in the current url

// /v1/catalog/datacenters
[
    "${location.pathname.get(1)}"
]
// yields
[
    "catalog"
]

location.pathname.slice

location.pathname.isDir