Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit b55bf51

Browse files
authored
Merge pull request #30 from frejonb/add-options-request
add support for options verb
2 parents f12566c + 63a9b17 commit b55bf51

File tree

3 files changed

+66
-24
lines changed

3 files changed

+66
-24
lines changed

README.md

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,33 @@ The world-famous HTTP client [Request](https://github.com/request/request) now [
3131

3232
## Table of contents
3333

34-
* [Installation](#installation)
35-
* [Super simple to use](#super-simple-to-use)
36-
* [Browser compatibility](#browser-compatibility)
37-
* [Build your project with Webpack](#build-your-project-with-webpack)
38-
* [API in Detail](#api-in-detail)
39-
* [.request](#request)
40-
* [.defaults(options)](#defaultsoptions)
41-
* [.get(uri[,options])](#geturi-options)
42-
* [Crawl a webpage](#crawl-a-webpage)
43-
* [GET something from a JSON REST API](#get-something-from-a-json-rest-api)
44-
* [.getBuffer(uri[,options])](#getbufferuri-options)
45-
* [GET a buffer image](#get-a-buffer-image)
46-
* [.post(uri[,options])](#posturi-options)
47-
* [POST data to a JSON REST API](#post-data-to-a-json-rest-api)
48-
* [POST like HTML forms do](#post-like-html-forms-do)
49-
* [.put(uri[,options])](#puturi-options)
50-
* [.patch(uri[,options])](#patchuri-options)
51-
* [.delete(uri[,options])](#deleteuri-options)
52-
* [.head(uri[,options])](#headuri-options)
53-
* [.jar()](#jar)
54-
* [.cookie(str)](#cookiestr)
55-
* [Contributing](#contributing)
56-
* [Change History](#change-history)
57-
* [License](#license)
34+
- [Rx-Http-Request](#Rx-Http-Request)
35+
- [Table of contents](#Table-of-contents)
36+
- [Installation](#Installation)
37+
- [Super simple to use](#Super-simple-to-use)
38+
- [Browser compatibility](#Browser-compatibility)
39+
- [Build your project with Webpack](#Build-your-project-with-Webpack)
40+
- [API in Detail](#API-in-Detail)
41+
- [`.request`](#request)
42+
- [`.defaults(options)`](#defaultsoptions)
43+
- [`.get(uri[, options])`](#geturi-options)
44+
- [Crawl a webpage](#Crawl-a-webpage)
45+
- [GET something from a JSON REST API](#GET-something-from-a-JSON-REST-API)
46+
- [`.getBuffer(uri[, options])`](#getBufferuri-options)
47+
- [GET a buffer image](#GET-a-buffer-image)
48+
- [`.post(uri[, options])`](#posturi-options)
49+
- [POST data to a JSON REST API](#POST-data-to-a-JSON-REST-API)
50+
- [POST like HTML forms do](#POST-like-HTML-forms-do)
51+
- [`.put(uri[, options])`](#puturi-options)
52+
- [`.patch(uri[, options])`](#patchuri-options)
53+
- [`.delete(uri[, options])`](#deleteuri-options)
54+
- [`.head(uri[, options])`](#headuri-options)
55+
- [`.options(uri[, options])`](#optionsuri-options)
56+
- [`.jar()`](#jar)
57+
- [`.cookie(str)`](#cookiestr)
58+
- [Contributing](#Contributing)
59+
- [Change History](#Change-History)
60+
- [License](#License)
5861

5962
## Installation
6063

@@ -421,6 +424,25 @@ RxHR.head(uri).subscribe(...);
421424

422425
[Back to top](#table-of-contents)
423426

427+
### `.options(uri[, options])`
428+
429+
**Parameters:**
430+
> - ***uri*** *(required): The `uri` where request will be performed*
431+
> - ***options*** *(optional): Original [Request](https://github.com/request/request#requestoptions-callback) `options` object*
432+
433+
**Response:**
434+
> *[RxJS.Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md) instance*
435+
436+
Performs a request with `options` http method.
437+
438+
```typescript
439+
import {RxHR} from '@akanass/rx-http-request';
440+
441+
RxHR.options(uri).subscribe(...);
442+
```
443+
444+
[Back to top](#table-of-contents)
445+
424446
### `.jar()`
425447

426448
Creates a new `RxCookieJar` instance

src/lib/rx-http-request.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ export class RxHttpRequest {
184184
<CoreOptions> Object.assign({}, options || {}));
185185
}
186186

187+
/**
188+
* Function to do a OPTIONS HTTP request
189+
*
190+
* @param uri {string}
191+
* @param options {CoreOptions}
192+
*
193+
* @return {Observable<RxHttpRequestResponse<R>>}
194+
*/
195+
options<R = any>(uri: string, options?: CoreOptions): Observable<RxHttpRequestResponse<R>> {
196+
return <Observable<RxHttpRequestResponse<R>>> this._call<R>('options', <string> uri,
197+
<CoreOptions> Object.assign({}, options || {}));
198+
}
199+
187200
/**
188201
* Function that creates a new rx cookie jar
189202
*

test/unit/rx-http-request.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ describe('- Unit rx-http-request.test.ts file', () => {
9696
expect(RxHR.head(uri)).toBeInstanceOf(Observable);
9797
});
9898

99+
/**
100+
* Test options() method returns an Observable
101+
*/
102+
test('- `options` method must return an `Observable`', () => {
103+
expect(RxHR.options(uri)).toBeInstanceOf(Observable);
104+
});
105+
99106
/**
100107
* Test jar() method returns an Observable
101108
*/

0 commit comments

Comments
 (0)