Skip to content

Commit d108cf3

Browse files
author
Danny McCormick
authored
Add headers to rest response (microsoft#105)
* Add headers to rest response * Add test
1 parent 64e0f6c commit d108cf3

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

lib/RestClient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import util = require("./Util");
77

88
export interface IRestResponse<T> {
99
statusCode: number,
10-
result: T | null
10+
result: T | null,
11+
headers: Object
1112
}
1213

1314
export interface IRequestOptions {
@@ -200,6 +201,7 @@ export class RestClient {
200201
const response: IRestResponse<T> = {
201202
statusCode: statusCode,
202203
result: null,
204+
headers: {}
203205
};
204206

205207
// not found leads to null obj returned
@@ -226,6 +228,7 @@ export class RestClient {
226228
response.result = obj;
227229
}
228230
}
231+
response.headers = res.message.headers;
229232
}
230233
catch (err) {
231234
// Invalid resource (contents not json); leaving result obj null

make.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ target.samples = function () {
9696
run('tsc');
9797
run('node samples.js');
9898
run('npm install');
99-
run('npm start');
99+
run('npm run react');
100100
popd();
101101
console.log('done');
102102
}

package-lock.json

Lines changed: 8 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typed-rest-client",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Node Rest and Http Clients for use with TypeScript",
55
"main": "./RestClient.js",
66
"scripts": {

test/units/resttests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ describe('Rest Tests', function () {
4545
url: 'http://microsoft.com',
4646
data: null,
4747
json: null
48+
}, {
49+
'my-header': 'my-header-val'
4850
});
4951
let restRes: restm.IRestResponse<HttpData> = await _rest.get<HttpData>('http://microsoft.com');
52+
assert(restRes.headers['my-header'] === 'my-header-val', 'Response should include headers');
5053
assert(restRes.statusCode == 200, "statusCode should be 200");
5154
assert(restRes.result && restRes.result.url === 'http://microsoft.com');
5255
});

0 commit comments

Comments
 (0)