Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mockwave

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockwave

API proxy with mocking support

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
0
Weekly downloads
 
Created
Source

image

Mockwave

Have you ever had to delay your UI development to wait for a backend team to implement the APIs you need?

Mockwave lets you create mock API endpoints while seamlessly proxying all other requests to the real API, combining the flexibility of mocking with the reliability of a live backend.

While you wait for the API team to implement the new APIs you need for your UI development, you can create temporary endpoints that return mock or test data.

Mockwave is still in an early stage. I hope you find it useful but please feel free to open feature requests!

Getting started

Install Mockwave in your project:

npm install mockwave

Creating mock APIs

Mockwave uses Fastify under the hood for mock API routes. Routes are defined using Fastify handler functions. This gives you the full power of the Fastify framework. Your mock APIs can return static data or contain logic.

Mock APIs are defined in a JavaScript file. The convention is for the file name to end with .mock.js, but this is just a convention and is not required.

The file should have a default export which is a function. The function takes one argument, server, which is the underlying Fastify instance. From here, you can define your own mock endpoints and their data or behavior.

See the Fastify documentation for more details on adding routes.

Example

Here is an example mock file:

export default function myMock(app) {
    app.get('/api/test', (request, reply) => {
        reply
            .code(200)
            .send({ hello: 'world' });
    });
}

Using multiple mock files

You can split up your mocks into multiple .mock.js files. Just specify them as a space-separated list on the command line when you run Mockwave.

Running Mockwave

Once you have your mocks defined in a mock file, you can start Mockwave. You'll need the file name of the mock as well as the URL you want to proxy other requests to.

The structure of the command is:

npx mockwave -t <proxy target> <mock file name>

Assuming you want to proxy to https://httpbin.org and your mock file is called myMock.mock.js, the command is as follows:

npx mockwave -t https://httpbin.org myMock.mock.js

By default, Mockwave listens on port 8000. If you need a different port, you can specify the -p option and enter a different port number.

Now, when you send a request to http://localhost:8000, if it matches one of your mock routes, your mock will handle it. Otherwise, the request will be proxied to https://httpbin.org.

Keywords

FAQs

Package last updated on 27 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc