Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/psi-4ward/express-virtual-request
Mock `request` and `response` objects to run virtual requests against express.js
https://github.com/psi-4ward/express-virtual-request
Last synced: 22 days ago
JSON representation
Mock `request` and `response` objects to run virtual requests against express.js
- Host: GitHub
- URL: https://github.com/psi-4ward/express-virtual-request
- Owner: psi-4ward
- License: mit
- Created: 2015-01-26T12:49:47.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-29T13:14:16.000Z (over 9 years ago)
- Last Synced: 2024-12-09T08:46:45.235Z (25 days ago)
- Language: JavaScript
- Size: 190 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-virtual-request
Mock `request` and `response` objects to run virtual requests against express.js
```javascript
var app = require('express')();
app.get('/hello', function (req, res) {
res.send('Hello World!')
});var VirtualRequest = require('express-virtual-request').request;
var VirtualResponse = require('express-virtual-request').response;var req = new VirtualRequest({
method: 'GET',
url: '/users',
headers: {
'Accept': 'application/json'
}
});// Response needs the request obj
var res = new VirtualResponse(req);
res.on('finish', function () {
console.log(res.statusCode, res.statusMessage);
console.log(res.headers);
console.log('-------');
console.log(res.body);
});// put it into express middleware chain
app.handle(req, res);
```### Installation
```
npm install psi-4ward/express-virtual-request
```### ExpressVirtualRequest
```javascript
var req = new VirtualRequest({
method: 'GET', // HTTP-Method
url: '/users', // url
headers: { // Object with headers
'Accept': 'application/json'
},
httpVersion: '1.1',
connection: {
encrypted: false,
remoteAddress: '127.0.0.1'
},
body: 'content body for POST/PUT requests'
});
```## License
[MIT](LICENSE)