1.0.2 • Published 8 years ago

response-api v1.0.2

Weekly downloads
4
License
ISC
Repository
github
Last release
8 years ago

response-api

Library for standardizing the API responses.

Installation

npm install scapegoat --save

Usage

The library has multiple methods for different types of response

  1. success(message, object, session)
  • message: A description for the response that can be displayed on the client
  • object: Data that will be sent to the client (ex. User list, Porfile and so on)
  • session: Parameter that is checked to see if the user has an active session
responseApi.success('User successfully created', {
	fistName: "John",
	lastName: "Doe",
	email: "jdoe@does.io"
}, req.user);

{
	timestamp: "1447331318",
	hasSession: true,
	error: null,
	success: {
		message: "User successfully created",
		object: {
			fistName: "John",
			lastName: "Doe",
			email: "jdoe@does.io"
		}
	}
}
  1. error(message, code, session)
  • message: A description for the response that can be displayed on the client
  • code: Error code that is returned to the client to enhance the possiblity of customizing the client app error response
  • session: Parameter that is checked to see if the user has an active session
responseApi.error('Sorry, our server has failed us', 500, req.user);

{
	timestamp: "1447331318",
	hasSession: true,
	error: {
		message: "Sorry, our server has failed us",
		code: 500
	},
	success: null
}