Skip to content

Commit

Permalink
Support adding query params for DELETE. (microsoft#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejhayes authored May 11, 2020
1 parent 046b966 commit f8d4424
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/RestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class RestClient {
public async del<T>(resource: string,
options?: IRequestOptions): Promise<IRestResponse<T>> {

let url: string = util.getUrl(resource, this._baseUrl);
let url: string = util.getUrl(resource, this._baseUrl, (options || {}).queryParameters);
let res: httpm.HttpClientResponse = await this.client.del(url,
this._headersFromOptions(options));
return this.processResponse<T>(res, options);
Expand Down
9 changes: 6 additions & 3 deletions test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions test/tests/resttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,35 @@ describe('Rest Tests', function () {
assert(restRes.result && restRes.result.url === 'https://httpbin.org/delete');
});

it('deletes a resource passing Query Parameters', async () => {
this.timeout(3000);
const response: restm.IRestResponse<HttpBinData> = await _rest.del<HttpBinData>('https://httpbin.org/delete', _options);

assert(response.statusCode == 200, "statusCode should be 200");
assert(response.result.url === 'https://httpbin.org/delete?id=1&type=compact');

Object.keys(_options.queryParameters.params).forEach(key => {
const actual = response.result.args[key];
const expected = _options.queryParameters.params[key];

assert(expected == actual);
})
});

it('deletes a resource with baseUrl passing Query Parameters', async () => {
const response: restm.IRestResponse<HttpBinData> = await _restBin.del<HttpBinData>('delete', _options);

assert(response.statusCode == 200, "statusCode should be 200");
assert(response.result.url === 'https://httpbin.org/delete?id=1&type=compact');

Object.keys(_options.queryParameters.params).forEach(key => {
const actual = response.result.args[key];
const expected = _options.queryParameters.params[key];

assert(expected == actual);
})
});

it('does an options request', async() => {
let restRes: restm.IRestResponse<HttpBinData> = await _rest.options<HttpBinData>('https://httpbin.org');
assert(restRes.statusCode == 200, "statusCode should be 200");
Expand Down

0 comments on commit f8d4424

Please sign in to comment.