Giter Site home page Giter Site logo

axios-observable's People

Contributors

dependabot[bot] avatar lvbesien avatar ruudandriessen avatar songhuige avatar whazor avatar zdu-strong avatar zhaosiyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

axios-observable's Issues

- Upgrade Axios into 0.21.1

I got a build error because Axios that this package use is still using Axios 0.19, which has an SSRF vulnerability.

image

This security hole is fixed in the latest version of Axios: axios/axios#3410

Do you mind to update the Axios version to 0.21.1?

Export AxiosResponse through 'axios-observable';

Hi there,

Is it possible to re-export all the typings, such as AxiosResponse, that come from the axios inside axios-observable so we can use it like this:

import Axios, { AxiosResponse} from 'axios-observable';

Axios.get<string>(`some-url`).pipe(map((res: AxiosResponse) => res?.data));

Currently you can do it like the following:

import { AxiosResponse } from 'axios';
import Axios from 'axios-observable';

Axios.get<string>(`some-url`).pipe(map((res: AxiosResponse) => res?.data));

But that requires the extra axios package to be installed like this:

"axios": "^1.2.0",
"axios-observable": "^2.0.0",

Deploying the application will fail due to missing typings if the axios is not installed seperatly.

Anyway, great tool and thanks for all the work!

Issue building library using external rxjs

I'm building a library that uses axios-observable using rollup, and make rxjs an external dependency.

However, the built library contains a line like this:

import require$$0$1, { of, BehaviorSubject, Subject, timer, merge as merge$1, throwError, forkJoin } from 'rxjs';

When my library gets built into an Angular application, the build fails with an error like so:

./build/live-agent-core/live-agent-core.js:3655:15-27 - Error: export 'default' (imported as 'require$$0$1') was not found in 'rxjs' (possible exports: ArgumentOutOfRangeError, AsyncSubject, BehaviorSubject, ConnectableObservable, EMPTY, EmptyError, GroupedObservable, NEVER, Notification, NotificationKind, ObjectUnsubscribedError, Observable, ReplaySubject, Scheduler, Subject, Subscriber, Subscription, TimeoutError, UnsubscriptionError, VirtualAction, VirtualTimeScheduler, animationFrame, animationFrameScheduler, asap, asapScheduler, async, asyncScheduler, bindCallback, bindNodeCallback, combineLatest, concat, config, defer, empty, forkJoin, from, fromEvent, fromEventPattern, generate, identity, iif, interval, isObservable, merge, never, noop, observable, of, onErrorResumeNext, pairs, partition, pipe, queue, queueScheduler, race, range, scheduled, throwError, timer, using, zip)

I believe this is because there is a line:

const axios_1 = require("axios");

in node_modules/axios-observable/dist/create-observable.js

Would it be possible to build axios-observable for two different targets so that the require statement is replaced with an es6 import statement?

Redaxios

Hello!

Could it be possible to have an Axios Observable based on redaxios that has the same API as Axios?

Performing multiple requests with axios-observable

Hello,

This is not actually an issue but a question on how to properly manage multiple requests that should be resolved at once (like with promise.all()).

I've something like this:

import Axios from 'axios-observable';
import { AxiosObservable } from 'axios-observable/dist/axios-observable.interface';
import {forkJoin, from, Observable} from 'rxjs';
import { AxiosResponse } from 'axios';

export interface IRequestOptions {
  skipAuthHeader?: boolean;
}

const get = <T>(url: string, opts?: IRequestOptions): AxiosObservable<T> => {
  return Axios.get<T>(url, getRequestConfig(opts));
};

const getAll = <T>(urls: string[], opts?: IRequestOptions): Observable<AxiosResponse[]> => {
  return forkJoin(
    urls.map(url => from(Axios.get<T>(url, getRequestConfig(opts))))
  );
}

While this is working fine, I don't like to have different returned types. I actually want to wrap get and getAll methods together, although maybe I've not think on this properly.

On the other hand, I'm not sure if with this approach I'm losing the advantages of AxiosObservable like cancel the pending requests when all subscriptions have been cancelled.

So, the questions here is, do you have some advice or workaround on how to manage this situations?

Thanks!

Errors when using Axios 1.x.x

Thank you very much for the excellent library!

Errors occurred while migrating to Axios 1.2.1 with axios-observable 2.0.0

Stackblitz Case (Bug Reports)
https://stackblitz.com/github/dbelob/axios-observable-cancel-token-error

Current behavior
Error when trying to make HTTP request and error message in console.

In Firefox:
image

In Chrome and Edge:
image

In Stackblitz:
image

Expected behavior
Successful completion of the HTTP request, displaying a message in the browser, no error messages in the console:
image
See example with Axios 0.27.2 https://stackblitz.com/github/dbelob/axios-observable-cancel-token-error/tree/axios-0.27.2

  • axios-observable version: 2.0.0

  • Axios version: 1.2.1

  • Node.js version: 18.12.1

  • OS version: Windows 8.1, Windows 10

  • Browser: Firefox 107.0.1, Chrome 108.0.5359.99, Edge 108.0.1462.46

Update Axios peer dependency

I have issues using axios-observable with latest Axios installed. To reproduce:

$ mkdir /tmp/deptest
$ cd /tmp/deptest
$ yarn add axios axios-observable rxjs

Which results in:

yarn add v1.22.17
info No lockfile found.
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
warning " > [email protected]" has incorrect peer dependency "axios@^0.21.1".
[4/4] ๐Ÿ”จ  Building fresh packages...
success Saved lockfile.
success Saved 4 new dependencies.
info Direct dependencies
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ””โ”€ [email protected]
info All dependencies
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ””โ”€ [email protected]
โœจ  Done in 0.80

You can see the warning:

warning " > [email protected]" has incorrect peer dependency "axios@^0.21.1".

Which is odd to me because the version range is setup correctly using ^. Not quite sure why it is still failing.

Usage with react-query

Hi,

I am trying to integrate this library with react-query. I know that react-query only works with promises and axios-observable returns an observable. Is there a way for me to get it working?

README example mistake

In the example, isn't the following:

Axios.get('/user?ID=12345'), {
    params: {
      ID: 12345
    }
  })
  [...]

supposed to be:

Axios.get('/user'), {
    params: {
      ID: 12345
    }
  })
  [...]

Apply interceptors to a custom Axios instance

I'm got this error when trying to apply interceptors to a custom Axios instance - Property 'interceptors' is a static member of type 'Axios'.

const instance = Axios.create();
instance.interceptors.request.use(function () {/*...*/});```

Cancellation

I think Cancellation isn't working well. because it's not cancell te request to the server or I'm not right?

Export AxiosObservable in main index.ts file

Hi, thanks for making this wonderful module.
What I'm currently doing is like below:

jobs$
  .pipe(
    mergeMap<string, AxiosObservable<string>>(
      (url = 'https://www.baidu.com') => {
        return Axios.get(url);
      },
    ),
    map((result) => result.data),
    tap((html) => {
      console.log(html);
    }),
  )

So I need to specify the input and output data type of mergeMap function in order to get it work. In that case I need to import AxiosObservable. Is this the best way to use it? If AxiosObservable is needed, can you please export it in the main project file, instead of 'axios-observable/dist/axios-observable.interface'?
Something like this would be fine:

import { AxiosObservable } from 'axios-observable';

Doesn't work with the latest Axios 1.1.3 (wants 0.27.0)?

Hi! Seems axios-observable wants a very old version of axios (0.27.0) -- could this be updated?

node: v18.4.0
npm:8.19.2

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: @xxx/xxx:
npm ERR! Found: [email protected]
npm ERR! node_modules/axios
npm ERR! axios@"^1.1.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer axios@"^0.27.0" from [email protected]
npm ERR! node_modules/axios-observable
npm ERR! axios-observable@"*" from the root project

Typescript Property 'observable' does not exist on type 'SymbolConstructor'.

I am doing a POC install of axios-observable in a Vue based application and I'm getting the following error:

    45:13 Property 'observable' does not exist on type 'SymbolConstructor'.
    43 | export declare type ObservableLike<T> = InteropObservable<T>;
    44 | export declare type InteropObservable<T> = {
    45 |     [Symbol.observable]: () => Subscribable<T>;
    46 | };
    47 | /** OBSERVER INTERFACES */
    48 | export interface NextObserver<T> {

Version: typescript 3.9.6

After a quick search I can see that this is an error introduced in Typescript that affected a lot of packages.

I would like to know if this is a known error for 'axios-observable' and is there a patch/fix coming?

Thanks

(SOLVED) Cannot make GET request when using a custom httpClient Facade

Hy @zhaosiyang

I'm working on implementing a httpClient similar to the one from Angular and found this library.
The httpClient is a service that will be injected in other services and basically acts like a facade for the axios lib.

import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { Axios } from  'axios-observable';

// httpClient Class
export class HttpClient {
protected readonly instance: AxiosInstance;
constructor(
        @inject('ApiBaseUrl') baseURL: string
    ) {
        this.instance = Axios.create({
            baseURL
        })

   this.get = this.instance.get;
   // other methods go here

  }
}

I also have some interceptors inside the class.

It works fine with plain axios but as I want to make all the requests observable and not promises I'm using the lib you created.

There are several errors that I'm encountering:

  1. TS2739: Type 'Axios' is missing the following properties from type 'AxiosInstance': getUri, options
    When trying to create an instance using Axios from axios-observable instead with the AxiosInstance

Now, this is simple to fix, just remove the type of the instance

protected readonly instance;
  1. index.js:51 Uncaught TypeError: Cannot read property 'get' of undefined
    at HttpClient../node_modules/axios-observable/dist/index.js.Axios.get (index.js:51)

Looking at the compiled code:

 Axios.prototype.get = function (url, config) {
        return create_observable_1.createObservable(this.axiosInstance.get, url, config);
    };

I can see that axiosInstance is not available. I will proceed in investigating more and try to find a fix.
I'm using the following versions:
axios: 0.20.0
axios-observable: 1.1.3

Lambda execution failed. Error: Cannot find module 'axios-observable'

Lambda execution failed with status 200 due to customer function error: Error: Cannot find module 'axios-observable' Require stack: - /var/task/src/handlers/handler.js - /var/runtime/UserFunction.js - /var/runtime/index.js. Lambda request id: cac503cb-a8eb-4031-b472-3df40dc53857

Missing license file

@zhaosiyang Hi is it possible to add LICENSE file inside the repo and release new patch version with the license?

MIT License requires to distribute full license text along the source code so right now this is actually proprietary code and cannot be legally used by anyone.

So if you would be able to add LICENSE.md file with this text https://opensource.org/licenses/MIT it would be great.

Thanks a lot

Interceptors not working

I'm trying to intercept 401 errors, but interceptors doesn't work.

My code:

      Axios.interceptors.response.use((response) => response, (error) => console.log('>>>', error));

        this.instance = Axios.create({
            baseURL: BASE_URL,
            timeout: 10000,
            headers: {
                Authorization: `Bearer ${token}`,
                'Access-Control-Allow-Headers': 'Authorization'
            }
        });

Mocking axios-observable with Jest

I have an issue when i try to mock axios-observable with jest.
jest.mock("axios-observable", () => Object.assign( jest.fn(), { get: jest.fn() } ));

Here's how i try to mock it.
But i got an error when executing my test saying :
'TypeError: _axiosObservable.default.get(...).pipe is not a function'
Any idea of what going wrong or any exemple of mocking exemple implementation ?

Thanks by advance,
Best Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.