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

@open-rpc/mock-server

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@open-rpc/mock-server

Provides a mock JSON-RPC API given an OpenRPC Document

  • 1.7.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.4K
increased by71.04%
Maintainers
2
Weekly downloads
 
Created
Source

open-rpc-mock-server

CircleCI branch npm GitHub release GitHub commits since latest release

Provide a Mock server for an OpenRPC Document.

Features

Basic Mode

Given an OpenRPC document, Mock server will provide a mock implementation of the JSON-RPC api that:

Service Mode

Running the mock server in service mode will run a JSON-RPC service that:

  • implements one method: mock. It takes an openrpc document, returns a url path postfix. Appending the path to the services url will give us a mock server for the document provided.
  • host it yourself or use the OpenRPC hosted one: https://mock.open-rpc.org

CLI & Javascript/Typescript API

Mock server is generally meant to be run via CLI, however it can also be imported to your project. doing so will:

  • give you a function to start the server, and returns you the OpenRPC Server instance
  • from there you can add transports, routers & middleware

Install

CLI

npm i -g @open-rpc/mock-server

Javascript API

npm i -S @open-rpc/mock-server

Usage

CLI

Defaults

The default settings expect to find a file in the root of your project called open-rpc.json. It will must be a valid OpenRPC document as validated by OpenRPC Metaschema, or an error will be returned.

npm run mock-server

this will start an HTTP server on http://localhost:3333 (default settings)

Custom path or filename

Where my-open-rpc-document.json is a file in the current directory which is a valid OpenRPC document as validated by OpenRPC Metaschema.

open-rpc-mock-server -d my-open-rpc-document.json
OpenRPC Document from url

You can also provide a URL that will resolve the OpenRPC document in JSON format:

open-rpc-mock-server -d https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/simple-math-openrpc.json
Running in Service Mode

Allows you to add documents to the running server as a JSON-RPC request. One mock server in service mode can handle a large number of mocked services at once with this configuration.

open-rpc-mock-server --mode service

A server is running on http://localhost:3333 now. You can call the mock method, and pass it your OpenRPC document, which will start mocking that service (under the returned url path).

Trying out the mocked service

  • Try out the free to use OpenRPC-hosted mock server https://mock.open-rpc.org/ here
  • use your own localhost mock server with playground here
  • or try the postman-like only interface OpenRPC Inspector with any of the above links

Example

Contributing

How to contribute, build and release are outlined in CONTRIBUTING.md, BUILDING.md and RELEASING.md respectively. Commits in this repository follow the CONVENTIONAL_COMMITS.md specification.

FAQs

Package last updated on 09 May 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