0.2.1 • Published 1 year ago

next-response-helpers v0.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

next-response-helpers

Functions to make NextJS API and SSR responses more concise

Exports the following helpers:

import {NextApiResponse} from "next";

export const res403 = (res: NextApiResponse, message?: string) => res.status(403).send(message || "Unauthed");
export const res400 = (res: NextApiResponse, message?: string) => res.status(400).send(message || "Missing parameters");
export const res500 = (res: NextApiResponse, e: Error) => res.status(500).json({error: e});
export const res405 = (res: NextApiResponse, message?: string) => res.status(405).send(message || "Method not allowed");
export const res404 = (res: NextApiResponse, message?: string) => res.status(404).send(message || "Resource not found");
export const res200 = (res: NextApiResponse, data?: any) => res.status(200).json(data || {});
export const ssrRedirect = (destination: string) => ({redirect: {permanent: false, destination: destination}});
export const ssr404: {notFound: true} = {notFound: true};

Contributions welcome at https://github.com/wwsalmon/next-response-helpers

0.2.1

1 year ago

0.2.0

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago