reactive-http
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Reactive HTTP devel npm npm docs

HTTP Fetch API client over RxJS Observables inspired by Angular HttpClient.

Install

npm install rxjs@^7 reactive-http --save
# or
yarn add rxjs@^7 reactive-http

Usage

// import { catchError, of } from 'rxjs'
import { Observable } from 'rxjs'
import { Http, HttpHandler, HttpInterceptor } from 'reactive-http'

class Interceptor1 implements HttpInterceptor {
    intercept(req: Request, next: HttpHandler): Observable<Response> {
        console.log("first interceptor!")
        return next(req)
    }
}

class Interceptor2 implements HttpInterceptor {
    intercept(req: Request, next: HttpHandler): Observable<Response> {
        console.log("second interceptor!")
        return next(req)
    }
}

interface Repository {
    id: number,
    name: string,
    description: string,
    html_url: string,
}

const http = new Http()
http.intercept(new Interceptor1())
http.intercept(new Interceptor2())

const ob$ = http.get<Repository>('https://api.github.com/repos/joseluisq/reactive-http')
// .pipe(
//     catchError(err => {
//         console.error(err)
//         return of({ error: false, message: err.message })
//     })
// )

ob$.subscribe(resp => {
    console.log('id:', resp.id)
    console.log('name:', resp.name)
    console.log('description:', resp.description)
})

API

See reactive-http documentation page.

Contributions

Feel free to send a Pull request or file an issue.

License

MIT license

© 2023-present Jose Quintana

Package Sidebar

Install

npm i reactive-http

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

24.2 kB

Total Files

19

Last publish

Collaborators

  • joseluisq