Skip to content

TractorZoom/http-response

Repository files navigation

@tractorzoom/http-response

Library to build http responses for use in serverless projects

Commitizen friendly jest Prettier Renovate enabled semantic-release

pull_request_verify publish

Available Methods

Method: createResponse(body, status)
parameter type required description
body any no the body to be stringified and sent with the response
status number no status code of the response
Method: badRequest(body = {message: 'Bad Request'})
parameter type required description
body any no the body to be stringified and sent with the response, default above in method signature
Method: internalServerError(body = {message: 'Internal Server Error'})
parameter type required description
body any no the body to be stringified and sent with the response, default above in method signature
Method: methodNotAllowed(body = {message: 'Method Not Allowed'})
parameter type required description
body any no the body to be stringified and sent with the response, default above in method signature
Method: notFound(body = {message: 'Not Found'})
parameter type required description
body any no the body to be stringified and sent with the response, default above in method signature
Method: ok(body = {message: 'OK'})
parameter type required description
body any no the body to be stringified and sent with the response, default above in method signature

How do I use? 🤔

Installation:
npm i @tractorzoom/http-response@latest
Usage:
import { executeQuery } from '@tractorzoom/serverless-mysql-utils';
import { ok, internalServerError } from '@tractorzoom/http-response';

export const handler = async () => {
    const queryString = `SELECT * FROM MyTable WHERE id = "some-guid"`;

    const response = await executeQuery(queryString);

    if (response.error) {
        return internalServerError(response);
    }

    return ok(response);
};

About

http responses designed to work with API Gateway and Lambda

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 8