0.2.5 • Published 7 years ago

api-middleware-response v0.2.5

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

API Middleware Response

Middleware for API HTTP Response

Build Status npm License Coverage Status

Install

$ npm install api-middleware-response --save

Setup

var express = require('express')
var apiresponse = require('api-middleware-response');
var app = express();

app.use(apiresponse());
app.listen(3000);

How to use

Example with object

app.get('/', function(req, res) {
  var data = { 
    id: 10,
    name: "Renato"
  };
  
  res.data.setObject(data);
}

Output

{
    "id": "10",
    "name": "Renato"
}

Example with array object

app.get('/', function(req, res) {
  var data = [
  { 
    "id": "10",
    "name": "Renato"
  },
  { 
    "id": "20",
    "name": "André"
  }
  ];
  
  res.data.setArrayObject(data);
}

Output

{
  "success": "true",
  "paging": {
    "total": "2",
    "pages": "1",
    "currentPage": "1",
    "perPage": "15"
  },
  "data": [
  { 
    "id": "10",
    "name": "Renato"
  },
  { 
    "id": 20,
    "name": "André"
  }
  ]
}

Roadmap

License

Licensed under the MIT License.

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago