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

lambdaserverlessrequest

v1.0.3

Published

LambdaServerlessRequest provides an easy way to make requests to a Lambda serverless function instead of having to use API Gateway, with major interface inspiration from axios.

Downloads

5

Readme

LambdaServerlessRequest Build Status Coverage Status Known Vulnerabilities Dependencies Dev Dependencies NPM version

General

LambdaServerlessRequest is an easy way to make requests to a Lambda serverless function instead of having to use API Gateway. LambdaServerlessRequest was heavily inspired by axios, and although there is not complete feature parity, and there are some interface changes, coming from axios to LambdaServerlessRequest will feel very natural.

Installation

$ npm i lambdaserverlessrequest

Examples

const serverlessRequest = require("lambdaserverlessrequest");

const request = serverlessRequest.create({
  "lambda": new AWS.Lambda({"region": "us-west-2"})
});

try {
  const result = await request({
    "method": "get",
    "functionName": "MyLambdaFunction1",
    "url": "/api/books"
  }));
  console.log(result);
} catch (e) {
  console.error(e);
}

try {
  const result = await serverlessRequest({
    "method": "post",
    "functionName": "MyLambdaFunction1",
    "url": "/api/books",
    "data": {"id": 1, "title": "The best book ever"}
    "lambda": new AWS.Lambda({"region": "us-west-2"})
  }));
  console.log(result);
} catch (e) {
  console.error(e);
}

Instance Methods

  • lambdaServerlessRequest#request(config)
  • lambdaServerlessRequest#get(url[, config])
  • lambdaServerlessRequest#delete(url[, config])
  • lambdaServerlessRequest#head(url[, config])
  • lambdaServerlessRequest#options(url[, config])
  • lambdaServerlessRequest#post(url[, data[, config]])
  • lambdaServerlessRequest#put(url[, data[, config]])
  • lambdaServerlessRequest#patch(url[, data[, config]])
  • lambdaServerlessRequest#create(config)

Request Config

{
  // `url` is the server URL that will be used for the request
  url: '/user',

  // `method` is the request method to be used when making the request
  method: 'get', // default

  // `functionName` is the name of the Lambda function you wish to run for this request
  functionName: 'MyLambdaFunction1',

  // `headers` are custom headers to be sent
  headers: {'X-Requested-With': 'XMLHttpRequest'},

  // `params` are the URL parameters to be sent with the request
  // Must be a plain object
  params: {
    ID: 12345
  },

  // `data` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', and 'PATCH'
  // Must be of one of the following types:
  // - string, plain object
  data: {
    firstName: 'Steve'
  },

  // `responseType` indicates the type of data that the server will respond with
  // options are: 'arraybuffer', 'json'
  responseType: 'json', // default

  // `validateStatus` defines whether to resolve or reject the promise for a given
  // HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
  // or `undefined`), the promise will be resolved; otherwise, the promise will be
  // rejected.
  validateStatus: function (status) {
    return status >= 200 && status < 300; // default
  }
}

Response Schema

{
  // `data` is the response that was provided by the server
  data: {},

  // `status` is the HTTP status code from the server response
  status: 200,

  // `headers` the headers that the server responded with
  // All header names are lower cased
  headers: {}
}

Major Differences Between LambdaServerlessRequest and axios

General

  • Currently query parameters attached to the url won't be recognized
  • Browser not supported
  • Requires Node.js version 8 or higher
  • We have currently only tested using async/await syntax, most functionality should work with promises, but this has not been tested at this point

Instance Methods

Removed/Not Present:

  • getUri
  • all
  • spread

Request Config

Added:

  • functionName
  • lambda

Changed:

  • params must be a plain object, URLSearchParams is not supported
  • body only accepts String or plain Object as types
  • responseType only accepts json and arraybuffer

Removed/Not Present:

  • baseURL
  • transformRequest
  • transformResponse
  • paramsSerializer
  • timeout
  • withCredentials
  • adapter
  • auth
  • responseEncoding
  • xsrfCookieName
  • xsrfHeaderName
  • onUploadProgress
  • onDownloadProgress
  • maxContentLength
  • maxRedirects
  • socketPath
  • httpAgent
  • httpsAgent
  • proxy
  • cancelToken

Response Config

Removed/Not Present:

  • statusText
  • config
  • request