UNPKG

735 BJavaScriptView Raw
1'use strict';
2
3const Client = require('..');
4const client = new Client();
5
6client
7
8 .before((req, next) => {
9 console.log('\n======================\nbefore:\n\n' + req.toString());
10 next(null, req);
11 })
12
13 .after(parseBody)
14 .after((res, next) => {
15 console.log('\n======================\nafter:\n\n' + res.toString());
16 next(null, res);
17 })
18
19 .get('http://httpbin.org/html')
20
21 .then(
22 res => console.log('\n======================\ndone:\n\n' + res.toString()),
23 err => console.log(err)
24 )
25
26;
27
28function parseBody(res, next) {
29 let body = '';
30
31 res.body.on('data', function (data) {
32 body += data.toString();
33 });
34
35 res.body.on('end', function () {
36 res.body = body;
37 next(null, res);
38 });
39
40}
\No newline at end of file