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

@lifeomic/alpha

v7.0.3

Published

Unified client for HTTP services.

Downloads

86,911

Readme

alpha

License Build Status Coverage Status Greenkeeper badge Known Vulnerabilities PRs Welcome

Alpha is a module that provides a single client interface for interacting with HTTP micro-services regardless of whether they are implemented as Lambda functions or real HTTP servers.

API

Alpha instances are axios clients at their core. This means that they support the full axios API. The difference is how Alpha instances are instantiated. Regardless of how an Alpha instance is instantiated, requests to fully qualified HTTP URLs will always perform a real HTTP request. Requests made to Lambda functions with a Buffer payload will automatically encode the request body using the base64 encoding.

new Alpha(target)

Creates a new Alpha instances. All Alpha instances support the full axios API.

HTTP Targets

When an Alpha instance is created with an HTTP(S) base URL target, requests to unqualified URLs will be relative to the base URL. For example, the following code will dispatch the request to http://example.com/some/path.

const alpha = new Alpha('http://example.com');
const response = await alpha.get('/some/path');

Lambda Function Targets

When an Alpha instance is created with a base URL using the lambda scheme, requests to unqualified URLs will cause the specified Lambda function to be invoked with a synthetic API Gateway event using the optional Lambda alias. For example, the following code will invoke the test-function Lambda function with the named-alias.

const alpha = new Alpha('lambda://test-function:named-alias');
const response = await alpha.get('/some/path');

The lambda URL scheme is interpreted according to the following pattern:

    lambda://<function-name>:<named-alias>

Lambda Handler Targets

When an Alpha instance is created with a handler function target, requests to unqualified URLs will be transformed into synthetic API Gateway (v1) events that will be passed directly to the handler function. This is primarily used for unit testing Lambda handlers.

const alpha = new Alpha(handlerFunction);
const response = await alpha.get('/some/path');

Request Retries

An Alpha client can be configured to retry a failed attempt. A retryable failure currently means a request that failed from a network error or had a 5xx status code.

// Retry failed requests using default settings
const alpha = new Alpha('http://example.com', { retry: true });
// Retry failed requests using custom settings
const alpha = new Alpha('http://example.com', { retry: {
    attempts: 3,        // The number of attempts to make (default 3)
    factor: 2,          // The factor to use for the exponential backoff delay (default 2)
    maxTimeout: 10000,  // The max timeout in milliseconds to delay before the next attempt (default 10000)
    retryCondition: function (error) { } // If function result is truthy, the error will be retried (default is retry network and 5xx errors)
  });

Mocking Lambda

To redirect the Lambda requests to a mocked implementation, either set the LAMBDA_ENDPOINT environment variable, or use the lambdaEndpoint config option:

const alpha = new Alpha('lambda:my-lambda', { 
  lambdaEndpoint: 'http://localstack:4566'
});

The value of this option will be used when creating the AWS Lambda client.

Alpha.dockerLambda(options, clientOptions)

Creates an Alpha client instance that dispatches requests to docker-lambda. This facilitates testing Lambda services in a full mock Lambda environment running in a docker container. The options are passed to the docker-lambda library and the clientOptions configure the Alpha client instance that is created.