Skip to content

Commit

Permalink
fix: update versions of dependencies
Browse files Browse the repository at this point in the history
Make sure that the library works with RxJS v6+. Compatibility with older versions has not been assessed.

BREAKING CHANGE: The names of the imports have changed and now the camelcase identifies the default instance (vs the class)
  • Loading branch information
davguij committed Jun 20, 2020
1 parent 8e86a31 commit 93c04f7
Show file tree
Hide file tree
Showing 11 changed files with 9,509 additions and 15 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: CI
on: [push]

jobs:
lint_test:
runs-on: ubuntu-latest
name: Run tests
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Use Node 12
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Use cached node_modules
uses: actions/cache@v1
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
nodeModules-
- name: Install dependencies
run: npm ci
env:
CI: true

- name: Install peer dependencies
run: npm i axios rxjs
env:
CI: true

- name: Test
run: npm test
env:
CI: true

build:
runs-on: ubuntu-latest
name: Build
needs: lint_test
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Use Node 12
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Use cached node_modules
uses: actions/cache@v1
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
nodeModules-
- name: Install dependencies
run: npm ci
env:
CI: true

- name: Build
run: npm run build
env:
CI: true

- uses: actions/upload-artifact@v2
name: Store dist folder to artifacts
with:
name: dist
path: dist/ # or path/to/artifact

release:
runs-on: ubuntu-latest
name: Release version to npm registry
needs: build
if: github.ref == 'refs/heads/master'
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Use Node 12
uses: actions/setup-node@v1
with:
node-version: 12.x

- uses: actions/download-artifact@v2
name: Load dist folder from artifacts
with:
name: dist
path: dist

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

release-dry:
runs-on: ubuntu-latest
name: Release version to npm registry
needs: build
if: github.ref != 'refs/heads/master'
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Use Node 12
uses: actions/setup-node@v1
with:
node-version: 12.x

- uses: actions/download-artifact@v2
name: Load dist folder from artifacts
with:
name: dist
path: dist

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release -d
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.log
.DS_Store
node_modules
.rts2_cache_cjs
.rts2_cache_esm
.rts2_cache_umd
dist
coverage
13 changes: 13 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tsconfig.json
.travis.yml
.nojekyll
src/
test/
.npmignore
package-lock.json
.prettierrc
.releaserc
.github
.vuepress
docs
coverage
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}
5 changes: 5 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"branches": [
"master"
]
}
128 changes: 113 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,125 @@
# TSDX Bootstrap
# Rxios

This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx).
### A RxJS wrapper for axios

## Local Development
[![npm](https://badgen.net/npm/v/rxios?color=red&icon=npm)]() [![bundlephobia](https://badgen.net/bundlephobia/minzip/rxios)]()

Below is a list of commands you will probably find useful.
Rxios makes the awesome [axios](https://github.com/axios/axios) library reactive, so that it's responses are returned as [RxJS](https://github.com/ReactiveX/rxjs) observables.

### `npm start` or `yarn start`
## Observables? Why?

Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.
Regular promises are cool, especially for HTTP requests in async/await functions.

<img src="https://user-images.githubusercontent.com/4060187/52168303-574d3a00-26f6-11e9-9f3b-71dbec9ebfcb.gif" width="600" />
However, Observables provide operators like map, forEach, reduce... There are also powerful operators like `retry()` or `replay()`, that are often quite handy.

Your library will be rebuilt if you make edits.
Observables also excel when we need to perform some kind of manipulation on the received data, or when we need to chain several requests.

### `npm run build` or `yarn build`
Lastly, Reactive stuff is what all the cool kids are doing.

Bundles the package to the `dist` folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
## Installation

<img src="https://user-images.githubusercontent.com/4060187/52168322-a98e5b00-26f6-11e9-8cf6-222d716b75ef.gif" width="600" />
`npm install axios rxjs rxios`

### `npm test` or `yarn test`
## Usage

Runs the test watcher (Jest) in an interactive mode.
By default, runs tests related to files changed since the last commit.
You can use Rxios by either

**instantiating the class yourself**

```javascript
import { Rxios } from 'rxios';
const rxios = new Rxios({ /* options here */ })
const request = rxios.get(url)...
```

**importing a "ready-to-use" generic instance**

```javascript
import { rxios } from 'rxios';
const request = rxios.get(url)...
```

In any case, please keep in mind that, when importing, `Rxios` refers to the class and `rxios` to the instance.

### Syntax details

```javascript
const { Rxios } = require('rxios');
// or import { Rxios } from 'rxios';

const http = new Rxios({
// all regular axios request configuration options are valid here
// check https://github.com/axios/axios#request-config
baseURL: 'https://jsonplaceholder.typicode.com',
});

// plain GET request
http.get('/posts').subscribe(
response => {
console.log(response); // no need to 'response.data'
},
err => {
console.error(err);
}
);

// GET request with query params
http
.get('/posts', { userId: 1 }) // you can pass an object as second param to the get() method
.subscribe(
response => {
console.log(response); // no need to 'response.data'
},
err => {
console.error(err);
}
);

// POST request
http
.post('/posts', {
// this object will be the payload of the request
userId: 1,
id: 1,
title:
'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
})
.subscribe(
response => {
console.log(response); // again, no need to 'response.data'
},
err => {
console.error(err);
}
);
```

## TypeScript usage

Rxios is written in TypeScript, and its typings are provided in this same package.

Also, just like with axios or with Angular's Http module, response types are accepted by the method, like:

```typescript
import { Rxios } from 'rxios';
const http = new Rxios();
interface MyResponse = {userId: number; id: number; title: string};
http.get<MyResponse[]>('/posts/1')
.subscribe(resp: MyResponse[] => {...});
```

## Advanced usage

All Rxios methods always return an Observable, to which we can apply advanced RxJS operations.

For example, we could make two simultaneous requests and merge their responses as they come, without needing to wait for both to be completed.

```javascript
import { Observable } from 'rxjs/Rx';
import { Rxios } from 'rxios';
const http = new Rxios();

const firstReq = http.get('/posts/1');
const secondReq = http.get('/posts/2');
firstReq.merge(secondReq).subscribe(...);
```
Loading

0 comments on commit 93c04f7

Please sign in to comment.