npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@open-rpc/mock-server

v1.7.8

Published

Provides a mock JSON-RPC API given an OpenRPC Document

Downloads

23,005

Readme

open-rpc-mock-server

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:

  • implements all of the methods specified in the given OpenRPC document.
  • when calling a method with params used in an example, the example's result will be returned.
  • params without examples will have their results generated according to the method.result.schema: JSONSchema.
  • validates input params against their respective JSONSchemas.
  • Provides rpc.discover for service discovery-based integration testing.

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.