Skip to content

An opinionated way of standardizing a JSON response from an API

License

Notifications You must be signed in to change notification settings

leothelocust/custom-output

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

custom-output

An opinionated way of standardizing a JSON response from an API

Requirements

  • Typescript
  • Express

Method Signature

FormatOutput(
    response: any, // express response object
    error?: Error, // new Error("Message Goes Here")
    data?: any, // your API data
    successStatusCode?: number, // 200, 201, etc...
    errorStatusCode?: number, // 400, 500, etc...
    optionalMeta?: any // link params or additional data like offset, limit, etc...
): any

Very Basic Example

import express from 'express'
import {FormatOutput} from 'custom-output'

... all the express stuff here...

app.get('/', (req, res) => {
    FormatOutput(res, null, null, 200);
})

...

About

An opinionated way of standardizing a JSON response from an API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published