All Projects → blueberryapps → vcr.js

blueberryapps / vcr.js

Licence: MIT license
Mock server with Proxy and Record support inspired by ruby VCR.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to vcr.js

Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (-7.32%)
Mutual labels:  mock-server, proxy-server, recording
Killgrave
Simple way to generate mock servers written in Go
Stars: ✭ 180 (+339.02%)
Mutual labels:  mock-server, proxy-server
Sgo
A dev server for rapid prototyping. Setting a directory to a static server.It provides a 404 neat interface for listing the directory's contents and switching into sub folders.
Stars: ✭ 194 (+373.17%)
Mutual labels:  mock-server, proxy-server
Endpoint2mock
Android library which simplifies mocking of Retrofit endpoints
Stars: ✭ 16 (-60.98%)
Mutual labels:  mock-server
http-knocking
🚪HTTP-Knocking hides a Web server and open it by knocking sequence: Hide Web server until your knocks
Stars: ✭ 28 (-31.71%)
Mutual labels:  proxy-server
main
Mocks Server monorepo
Stars: ✭ 109 (+165.85%)
Mutual labels:  mock-server
rdScreenRecordSDK-for-Windows
Windows录屏SDK
Stars: ✭ 19 (-53.66%)
Mutual labels:  recording
uos
United Open-libraries of Sound. United procedures for open-source audio libraries. For FPC/Lazarus/fpGUI/MSEgui.
Stars: ✭ 112 (+173.17%)
Mutual labels:  recording
thumbai
Go Mod Repository, Go Vanity Server and Proxy Server
Stars: ✭ 84 (+104.88%)
Mutual labels:  proxy-server
chuck
Lightweight proxy for REST API mocking and run integration test on mobile devices
Stars: ✭ 17 (-58.54%)
Mutual labels:  mock-server
nginx-reverseproxy
A simple implementation of a multidomain nginx reverse proxy, using Node apps.
Stars: ✭ 46 (+12.2%)
Mutual labels:  proxy-server
sparql-proxy
SPARQL-proxy: provides cache, job control, and logging for any SPARQL endpoint
Stars: ✭ 26 (-36.59%)
Mutual labels:  proxy-server
kb-proxy
kb-proxy 是一个可本地部署的、提供代理功能、接口测试管理、支持在线Mock、Host环境管理的在线工具平台。
Stars: ✭ 52 (+26.83%)
Mutual labels:  mock-server
LiveProxies
Asynchronous proxy checker
Stars: ✭ 17 (-58.54%)
Mutual labels:  proxy-server
proxy pool
A simple proxy pool
Stars: ✭ 73 (+78.05%)
Mutual labels:  proxy-server
p3y
A single binary reverse proxy written in go. It was developed for use in Kubernetes, to wrap services like Prometheus with simple BasicAuth and TLS encryption.
Stars: ✭ 15 (-63.41%)
Mutual labels:  proxy-server
proxy
An HTTP proxy server written in C# and targeting .NET Core 3.
Stars: ✭ 31 (-24.39%)
Mutual labels:  proxy-server
wiremock
A tool for mocking HTTP services
Stars: ✭ 5,239 (+12678.05%)
Mutual labels:  mock-server
mtproxy
Alpine-based Docker Image for Telegram MTProto Proxy
Stars: ✭ 89 (+117.07%)
Mutual labels:  proxy-server
midi-recorder
🎹 The easiest way to record MIDI. No install. Automatically records.
Stars: ✭ 38 (-7.32%)
Mutual labels:  recording

VCR.js CircleCI Dependency Status

Mock server with Proxy and Record support inspired by ruby VCR.

tl;dr

yarn add vcr.js
mkdir -p fixtures/users
echo '{"users": ["Tim", "Tom"]}' > ./fixtures/users/GET.default.json
yarn vcr -- -f ./fixtures

Now you can hit localhost:8100/users and get your JSON!

Terminal options

Use --help to get all the possible options:

yarn vcr -- --help

Output:

yarn vcr -- --fixturesDir [./fixtures]

Options:
  -h, --help         Show help                                         [boolean]
  -f, --fixturesDir  Directory where to load fixtures    [default: "./fixtures"]
  -p, --proxy        URL to real API
  -r, --record       Record proxied responses to fixtures dir          [boolean]
  --port                                                         [default: 8100]

Examples:
  -f ./fixtures -p https://ur.l/base -r  Load fixtures from directory, proxy not
                                         found fixtures to ur.l/base and success
                                         responses record back to fixtures
                                         directory

Resolving fixtures

When you hit the VCR.js server with a URL (e.g. GET http://localhost:8100/api/v1/users), the URL is translated to the path of the fixture file, consisting of a relative path to a directory and a file name, in this case {fixturesDir}/api/v1/users/GET.default.(json|js).

In general form:

{fixturesDir}/{endpointPath}/{method}.{variant}.(json|js)

With url query parameters (in variant name params must be sorted alphabetically, also encoded by encodeURIComponent):

{fixturesDir}/{endpointPath}/{method}.param1=value&param2=value.(json|js)

Example:

When accessing http://localhost:8100/api/v1/users?page=1&limit=10 it will ty to look for fixture:

{fixturesDir}/{endpointPath}/GET.limit=10&page=1.(json|js)

Dynamic route params

To match an endpoint with dynamic params, use {dynamicParam} as the directory name. If you would like to get the same response from both GET /users/1 and GET /users/42, create a file with the name {fixturesDir}/users/{id}/GET.default.json and you can reuse your fixture file for all users! As a bonus you can access these params in fixtures and customize the response by using a .js fixture (described below).

Custom responses of a single endpoint - Variants

What if you wanted to customize the response of a single endpoint? Just set a variants cookies with a list of desired variants separated by comma as the value, e.g. /api/v1/users/{id}/GET.variantName,/api/v1/projects/POST.otherVariant Stub server will find the corresponding cookie variant matching the request path and provide you with the correct fixture.

or you can also visit /variants in browsers and use /variants?add=XXX to add multiple variants to existing setup, /variants?set=XXX to override variants and set given values, /variants?clear=t to remove all variants from cookie

What fixture types are handled?

Currently supported fixture types are .json and .js. JS fixtures are basically handlers as you know them from expressjs/node. A simple template for a .js fixture:

module.exports = (req, res, next) => {
  res.status(400).json({error: 'Bad request :D'});
};

Proxy mode - fixture recording

If you specify a -p or --proxy URL, the stub server will look for local fixtures and if no fixture is found, it will proxy the request to the 'real API', streaming the response back and optionally saving it as a fixture.

Proxy + record mode

Together with proxy option you can add -r or --record. This will enable saving fixtures from a proxy locally on the disc. For example after running yarn vcr -- -f ./fixtures -p https://ap.io/ -r with an empty fixtures folder and hitting GET /users, response from https://ap.io/users is streamed to the client and is also saved in fixtures/users/GET.default.json.

Custom variants for recording

If you want to save fixtures from proxy under a custom variant, just set the record_fixture_variant cookie with any word you want as the value. With the record_fixture_variant=blacklistedUser cookie the recorded fixtures will be saved as {path}/GET.blacklistedUser.json.

Development

yarn test
yarn tslint
yarn start

Made with love by

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].