A set of TypeScript functions for creating HTTP responses with standardized formats.
This library provides a collection of functions related to http to be used in Spacecat development. The functions are designed to create responses with standardized formats, making it easier to maintain a consistent structure across different parts of your application.
Install the package using npm or yarn:
npm install @adobe/spacecat-shared-http-utils
or
yarn add @adobe/spacecat-shared-http-utils
Import the functions in your TypeScript file and use them to generate HTTP responses. Here's an example:
import {
ok,
noContent,
badRequest,
notFound,
internalServerError,
} from '@adobe/spacecat-shared-http-utils';
// Example usage
const successResponse: Response = ok('Request was successful');
const emptyResponse: Response = noContent();
const errorResponse: Response = badRequest('Invalid input');
const notFoundResponse: Response = notFound('Resource not found');
const serverErrorResponse: Response = internalServerError('Something went wrong');
Creates a successful response with an optional body.
Creates a response with no content and optional headers.
Creates a response for a bad request with an error message and optional headers.
Creates a response for a not found scenario with an error message and optional headers.
Creates a response for an internal server error with an error message and optional headers.
Feel free to contribute by opening issues or creating pull requests. Please follow the existing coding style and include tests when adding new features.
This project is licensed under the Apache 2.0 - see the LICENSE file for details.