npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-response-format

v1.2.1

Published

A package libary that can help users to manage the well format of all the APIs in thier projects.

Downloads

20

Readme

API Response Format Package

The API Response Format Package is a Node.js package that provides a standardized format for API responses. This package can be used to simplify the process of returning consistent and structured responses from API endpoints. Features.

  • Standardized response format for API endpoints
  • Customizable response fields and error messages
  • Easy integration with existing Node.js projects
  • Well-documented API and code

Installation

To install the API Response Format Package, simply run the following command:

npm install api-response-format

Usage

Using the API Response Format Package is straightforward. Simply import the package in your Node.js project and use the response function to return a standardized response from your API endpoints.

In the example, the response.invalidCredentials function is used to return a invalid credentials response. The response.dataFound function is used to return data response with success response code.

Example:
import { Response } from "api-response-format";
import express from 'express';
const app = express();
const port = 3000;

app.listen(port, () => console.log(`App listening on port ${port}!`))

app.get('/my-route', (req, res) => {
    let data = "Response Data Sample";
    res.send(Response.dataFound(data));
});

The API Response Format Package also provides a different response methods for returning responses when the client sends an invalid, unauthorized request to the API endpoint.

Available Methods

| Methods | Description | Response Format | Parameters | | ------ | ------ | ------ | ------ | | badRequest | Function: Bad request | return { status: 400, success: false, obj } | obj: required, that can be anything such as message or data object | customMessage | Function: Send custom message | return { status: 409, success: false, msg } | msg: required | logoutSuccess | Function: When user logged out sucessfully. | return {status: 200,success: true, message: 'You have been logged out successfully'} | msg: required, defaultValue: 'You have been logged out successfully' | unauthrized | Function: Unauthrized Access | return { status: 401, success: false, message: 'User is not authorized for this operation' } | msg: required, defaultValue: 'User is not authorized for this operation' | loginSuccess | Function: Successful Login | return { status: 200, success: true, message: 'You have been loggedIn successfully', data } | data: required | accessTokenUpdated | Function: Successful updation of Access Token | return { status: 200, success: true, message: 'Access Token Update successfully', data } | data: required | dataEncrypted | Function: Encrypt Data Successfully | return { status: 200, success: true, message: 'User Data Encrypt successfully' } | NA | dataSync | Function: Data Sync Successfully | return { status: 200, success: true, message: 'Data Sync successfully' } | NA | dataNotFound | Function: Data Not Found | return { status: 404, success: false, message: 'No record(s) found', data } | data: optional | dataFound | Function: Sucess or Data found | return { status: 200, success: true, message: 'Success', data } | data: optional | dataFoundWithPagination | Function: Success or Data found with pagination parameters | return { status: 200, success: true, message: 'Success', data: { list: data, totalPages, limit: parseInt(limit), totalRecords, currentPage } } | data, totalPages, limit, totalRecords, currentPage | notExists | Function: Data does not exists | return { status: 409, success: false, message: '${name} doesn't exits' } | name: required | dataAlreadyExists | Function: Data already exists with provided request | return { status: 409, success: false, message: '${name} already exits with provided ${data}' } | name: required, data: requied | intervalServerError | Function: Server error | return { status, success: false, message } | msg: optional (defaultValue: 'Something went wrong, please try again'), statusCode: optional (defaultValue: 500) | documentUpdated | Function: Document updated successfully | return { status: 200, success: true, message: 'Documents has been updated successfully' } | NA | dataCreated | Function: Data Created Successfully | return { status: 201, success: true, message: '${name} has been created successfully', data } | name: required, data: required | dataNotCreated | Function: There was an error while creating data | return { status: 500, success: false, message: 'Something went wrong while creating ${name}' } | name: required | dataUpdated | Function: Data has been updated successfully | return { status: 200, success: true, message: '${name} has been updated successfully', data } | name: required, data: required | dataNotUpdated | Function: There was an error while updating data | return { status: 500, success: false, message: 'Something went wrong while updating ${name}'} | name: required | dataDeleted | Function: Data has been deleted successfully | return { status: 200, success: true, message: '${name} has been deleted successfully'} | name: required | dataNotDeleted | Function: There was an error deleting the record | return { status: 500, success: false, message: 'Something went wrong while deleting ${name}'} | name: required

License

The API Response Format Package is open-source software licensed under the MIT License.