Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
aerabi committed Sep 17, 2021
1 parent 4ff38a7 commit 6ee6f2d
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
# RxJSx Request
[![tests](https://github.com/rxjsx/request/actions/workflows/node.yml/badge.svg)](https://github.com/rxjsx/request/actions/workflows/node.yml)
[![Tests](https://github.com/rxjsx/request/actions/workflows/node.yml/badge.svg)](https://github.com/rxjsx/request/actions/workflows/node.yml)
[![Coverage Status](https://coveralls.io/repos/github/rxjsx/request/badge.svg?branch=master)](https://coveralls.io/github/rxjsx/request?branch=master)
[![NPM Version](https://img.shields.io/npm/v/@rxjsx/request)](https://www.npmjs.com/package/@rxjsx/request)
[![NPM Bundle Size](https://badgen.net/bundlephobia/minzip/@rxjsx/request)](https://bundlephobia.com/package/@rxjsx/request@latest)

A simple RxJS-based HTTP client

## Install
```bash
npm install --save @rxjsx/request
```

## Usage

### TypeScript + RxJS
```typescript
import { request } from '@rxjsx/request';

interface GitHubAPIList {
current_user_url: string;
}

request.get<GitHubAPIList>('https://api.github.com/')
.subscribe(response => {
const list: GitHubAPIList = response.json();
console.log(list.current_user_url);
});
```

### JavaScript + Await
```typescript
const { request } = require("@rxjsx/request");

const response = await request
.get('https://httpbin.org/get')
.toPromise();
console.log(response.json());
```
Try it here: https://runkit.com/aerabi/rxjsx-request-await

## API
```typescript
export declare function request<T, R>(options: RequestOptions<T>): Observable<Response<R>>;
export declare namespace request {
function get<R>(url: string, headers?: Record<string, string>): Observable<Response<R>>;
function post<T, R>(url: string, body?: T, headers?: Record<string, string>): Observable<Response<R>>;
function put<T, R>(url: string, body?: T, headers?: Record<string, string>): Observable<Response<R>>;
function patch<T, R>(url: string, body?: T, headers?: Record<string, string>): Observable<Response<R>>;
function del<R>(url: string, headers?: Record<string, string>): Observable<Response<R>>;
}
```

## Notes
- No peer dependency RxJS is required. One can instantly subscribe to the
request result and consume it or case it into a promise. For none of these cases
RxJS needs to be installed on the consumer's machine. One would need RxJS to
use transformations on the response (e.g. map, tap, filter, reduce, catch error).
- The functions return a _singleton_ observable, meaning that the observable will
contain one element (otherwise would error out).

0 comments on commit 6ee6f2d

Please sign in to comment.