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

aldersonjs

v0.5.0

Published

Alderson.js is a utility for simulating responses from APIs. It can also act as a proxy to your real API, whilst acting as a middleman.

Downloads

3

Readme

Node.js Package Node.js Test License

Alderson.js

Introduction

Alderson.js is an API mocking utility, allowing for easy configuration via JSON files. Alderson is capable of supplying mock data, echoing requests back to the sender, forwarding requests to a backend endpoint and also introducing delays to requests.

By giving you more flexibility and control over API responses, testing your frontends is made easy.

Usage

AldersonJS can be invoked using npx. Simply run npx aldersonjs and then a list of the config jsons you want to host mock APIs for, as shown below:

npx aldersonjs <config1.json> <config2.json> //etc

Configuring Alderson

As mentioned previously, Alderson.js is configured via JSON files. Examples of which can be found in the examples directory. At the top level, these files look like the following:

{
    "origins": {
        "type": "object",
        "description": "defines a mapping of names to real APIs"
        "optional": true
    },
    "port": {
        "type": "integer",
        "description": "determines which port to host the mock API on",
        "optional": true,
        "default": 8080
    },
    "endpoints": {
        "type: "array",
        "description": "An array of all mock endpoints",
        "items": {
            "type": "Endpoint"
        }
        "optional": "only if 'actions' is defined"
    },
    "actions": {
        "type: "array",
        "description": "An array of actions to be performed for all methods and URIs",
        "items": {
            "type": "Action"
        }
        "optional": "only if 'endpoints' is defined"
    }
}

An Endpoint is defined as below:

{
    "uri": {
        "type": "string",
        "description": "The path that the endpoint will be hosted on, e.g. /api"
    },
    "method": {
        "type": "string",
        "description": "The HTTP method used to call this endpoint",
        "enum": ["get", "head", "post", "put", "delete", "connect", "options", "trace", "patch"]
    },
    "actions": {
        "type": "array",
        "description": "An array of actions to execute when this endpoint is called",
        "items": {
            "type": "Action"
        }
    }
}

An Action is defined as below:

{
    "type": {
        "type": "string",
        "description": "The type of action to execute",
        "enum": ["echo", "delay", "log", "origin", "static", "status_code"]
    },
    "parameters": {
        "type": "object",
        "description": "mapping of paramters for the action",
        "optional": true
    }
}

Action Types

As documented above, there are many different types of actions available in Alderson.js. Below is a description of what each action does, and the paramaters that can be configured for it:

Echo

Echoes the contents of the request body in the response body

Parameters

None

Delay

Inserts a delay before executing the next action

{
    "duration": {
        "type": "integer",
        "description": "Duration in milliseconds to delay"
    }
}

Log

Logs a message to Alderson.js's console

{
    "message": {
        "type": "string",
        "description": "The message to log to the console"
    }
}

Origin

Forwards messages to a remove origin and returns the response

{
    "origin": {
        "type": "string",
        "description": "Name of the origin, as defined in the origins block at the root of the config"
    },
    "uri": {
        "type": "string",
        "description": "The path on the remote origin to hit",
        "optional: true,
        "default": "defaults to the uri in the request"
    }
}

Static

Servers up static content

{
    "body": {
        "type": "string | object",
        "description": "The body of the response"
    },
    "content_type": {
        "type": "string",
        "description": "The value to return in the Content-Type header"
    }
}

Status Code

Sets the status code of the response

{
    "status_code": {
        "type": "integer",
        "description": "The status code to respond with"
    }
}

Authentication

Authenticates the request against an OIDC server.

{
    "origin": {
        "type": "string",
        "description": "Name of the origin, as defined in the origins block at the root of the config"
    }
}

Header

Adds a header to the response.

{
    "header": {
        "type": "string",
        "description": "The name of the header to be added to the response"
    },
    "value": {
        "type": "any",
        "description": "Content of the header"
    }
}