Skip to content

Generic API response object for consistent API output across services

License

Notifications You must be signed in to change notification settings

InterNACHI/standard-api-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Standard API Response

Build Status

This is a generic API response object for consistent API output across services. it is mostly meant for internal InterNACHI use, but anyone is welcome to use it.

Basic Usage

app.post('/users', function(req, res) {
	// Handle provided data and build new user object
	// ...

	// Create API response object
	var apires = new OkResponse(user, OkResponse.codes.CREATED, 'User successfully created.');

	// Send to client
	apires.send(res);
}

Response Format

HTTP/1.1 201 OK
Content-Type: application/json

{
	"ok": true,
	"message": "User successfully created.",
	"data": { ... },
	"httpCode": 201, // Same as HTTP response code
	"error": { ... } // Only present if "ok" == false
}

About

Generic API response object for consistent API output across services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published