nexus-req

Typescript library for normalizing server responses in full stack web applications

Introduction

nexus-req is a small library built to normalize server responses within full stack applications. It can be used in frameworks that do not provide a standard way of returning structured responses from server-side, such as Nuxtjs.

Installation

Bun

bun i nexus-req

NPM

npm i nexus-req

Usage.

sendServerResponse

Returns a structured response object that can be returned as server response.

import { sendServerResponse } from 'nexus-req';
import type { ErrorCodes } from 'nexus-req';

const response = sendServerResponse<ErrorCodes>(400, 'This user is unauthorized to access this information.');
console.log(response) 

/** 
    returns {
    ok: false
    status: 400
    message: 'This user is unauthorized to access this information.'
    data: null
    }
**/

Last updated