testapi-cli
v1.0.2
Published
A CLI tool to create mock APIs.
Downloads
8
Maintainers
Readme
testapi-cli
A CLI tool to create and manage mock API endpoints. It is designed mainly for frontend developers who want a simple way to test their application without setting up a backend server.
Features (current stage)
- Initialize project with a
testapi.jsonfile. - Add new endpoints with
--method,--path,--responseand--status(status code is optional). - The new endpoints are stored in
testapi.jsonfile. Duplicate entries are prevented. - Start a local server in your desired port.
- Call the added endpoints and get its response.
Installation
npm i testapi-cliUsage (current stage)
Guide
testapi-cli helpInitialize project:
testapi-cli init #creates testapi.json fileAdd endpoint
testapi-cli add --method GET --path /users --response '[{"id":123,"name":"virat"},{"id":456,"name":"kohli"}]' --status 200Rules:
- --method must be a valid HTTP method.
- --path must begin with '/'.
- --response must be valid JSON enclosed within single quotes.
- --status is optional (default: 200)
Start server
testapi-cli start --port 3000Rules:
- --port must be in the range 1024-65535
Call endpoint
GET http://localhost:3000/usersExpected response
[
{"id":123,"name":"virat"},
{"id":456,"name":"kohli"}
]Next steps
- Implement delay option for responses.
- Add
listandremovecommands.
