LONG VERSION

Why NAMS

NAMS is born for help people to easily mock request with ZERO config.

Can be used for developing frontend graphic stuff and don’t have an active backend server or used for testing like e2e, visual regression test etc etc

NAMS is based on Fastify

How it works

The structure of Mocks folder need to be created for simulate url path and in the final folder need to have a json or javascript index file.

When NAMS reach the last folder start to search a index.json file, if not exist start to search a index.js and try to exec the function passing down this params {request, reply, folderPath} and send the output.

If u want to use the fastify hook preHandler you need to create a file called prehandler.js and put it in the same folder where index.[json/js] is located.

Search Steps

1. Search prehandler.js and if present exec the function with this args: (request, reply, next)

2. Search index.json file and if present send it for answer

3. Search index.js file and if present exec the function with this args: {request, reply, folderPath} and send the function result for answer

Session

NAMS use fastify-session and u can use it on prehandler.js file. [DOC LINK]

Proxy

By default NAMS give a 404 code status when it can’t find a file. If u want to mock only some request you can set your custom proxy. In this case when NAMS can’t find a file, use your proxy address for retrieve the answer.

EXAMPLE

Path Folder

path folder structure

Prehandler.js

prehandler.js example

api/path/index.js

example api/path/index.js

GITHUB