Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
@middy/util
Advanced tools
@middy/util is a utility package that provides a set of helper functions and middlewares to simplify the development of AWS Lambda functions. It is part of the Middy middleware engine, which allows you to compose reusable middleware for your Lambda functions.
createError
The `createError` function helps in creating HTTP errors with a specified status code and message. This is useful for handling errors in a standardized way in your Lambda functions.
const { createError } = require('@middy/util');
const error = createError(400, 'Bad Request');
console.log(error);
jsonSafeParse
The `jsonSafeParse` function safely parses a JSON string into an object. If the string is not valid JSON, it returns `null` instead of throwing an error.
const { jsonSafeParse } = require('@middy/util');
const jsonString = '{"key": "value"}';
const parsedObject = jsonSafeParse(jsonString);
console.log(parsedObject);
normalizeHttpResponse
The `normalizeHttpResponse` function ensures that the HTTP response object conforms to the expected format, making it easier to handle responses in a consistent manner.
const { normalizeHttpResponse } = require('@middy/util');
const response = { statusCode: 200, body: 'Success' };
const normalizedResponse = normalizeHttpResponse(response);
console.log(normalizedResponse);
The `aws-lambda-middleware` package provides a collection of middleware functions for AWS Lambda. It offers similar functionalities to @middy/util, such as error handling and response normalization, but it is not as comprehensive in terms of utility functions.
The `lambda-middleware` package is another alternative that provides middleware for AWS Lambda functions. It focuses on simplifying common tasks like input validation, error handling, and response formatting, similar to @middy/util.
The `lambda-api` package is designed to help build RESTful APIs using AWS Lambda. It includes middleware support and offers functionalities like routing, error handling, and response formatting, making it a good alternative to @middy/util for API development.
Util component of the middy middleware, the stylish Node.js middleware engine for AWS Lambda
You can read the documentation at: https://middy.js.org/docs/intro/utilities
To install middy you can use NPM:
npm install --save @middy/util
For documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.
Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.
Licensed under MIT License. Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the Middy team.
FAQs
🛵 The stylish Node.js middleware engine for AWS Lambda (util package)
The npm package @middy/util receives a total of 174,620 weekly downloads. As such, @middy/util popularity was classified as popular.
We found that @middy/util demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.