From 0bd97ecda260d522f2e786c7e7a117314b7d2f98 Mon Sep 17 00:00:00 2001 From: Damien Cassan Date: Mon, 8 Aug 2016 18:15:13 +0200 Subject: [PATCH] feat(http): add options method to Http (#10540) Add options method to the Http object, which could be useful when using self-describing RESTful APIs. This closes #10500, closes #7918 --- modules/@angular/http/src/http.ts | 9 +++++++++ modules/@angular/http/test/http_spec.ts | 13 +++++++++++++ tools/public_api_guard/http/index.d.ts | 1 + 3 files changed, 23 insertions(+) diff --git a/modules/@angular/http/src/http.ts b/modules/@angular/http/src/http.ts index 53641d2924..d11a778526 100644 --- a/modules/@angular/http/src/http.ts +++ b/modules/@angular/http/src/http.ts @@ -186,6 +186,15 @@ export class Http { this._backend, new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Head, url))); } + + /** + * Performs a request with `options` http method. + */ + options(url: string, options?: RequestOptionsArgs): Observable { + return httpRequest( + this._backend, + new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Options, url))); + } } diff --git a/modules/@angular/http/test/http_spec.ts b/modules/@angular/http/test/http_spec.ts index a5d3224036..2b01e69eb7 100644 --- a/modules/@angular/http/test/http_spec.ts +++ b/modules/@angular/http/test/http_spec.ts @@ -310,6 +310,19 @@ export function main() { }); + describe('.options()', () => { + it('should perform an options request for given url', + inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + backend.connections.subscribe((c: MockConnection) => { + expect(c.request.method).toBe(RequestMethod.Options); + backend.resolveAllConnections(); + async.done(); + }); + http.options(url).subscribe((res: Response) => {}); + })); + }); + + describe('searchParams', () => { it('should append search params to url', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { diff --git a/tools/public_api_guard/http/index.d.ts b/tools/public_api_guard/http/index.d.ts index ff01b4185b..542e3a22b8 100644 --- a/tools/public_api_guard/http/index.d.ts +++ b/tools/public_api_guard/http/index.d.ts @@ -64,6 +64,7 @@ export declare class Http { delete(url: string, options?: RequestOptionsArgs): Observable; get(url: string, options?: RequestOptionsArgs): Observable; head(url: string, options?: RequestOptionsArgs): Observable; + options(url: string, options?: RequestOptionsArgs): Observable; patch(url: string, body: any, options?: RequestOptionsArgs): Observable; post(url: string, body: any, options?: RequestOptionsArgs): Observable; put(url: string, body: any, options?: RequestOptionsArgs): Observable;