Giter Site home page Giter Site logo

Async transforms about axios HOT 9 CLOSED

axios avatar axios commented on April 17, 2024
Async transforms

from axios.

Comments (9)

mzabriskie avatar mzabriskie commented on April 17, 2024

Can you give me an example of what you're trying to do with async transforms?

from axios.

kentcdodds avatar kentcdodds commented on April 17, 2024

I remember once wanting to make a request in a transform to get more info
for my model because the endpoint I was hitting didn't have everything I
needed for my model. $http supports this so that was helpful.

  • Kent C. Dodds
    Sent from my mobile device, please forgive any errors or brevity. (I may
    have used speech to text...)
    On Oct 19, 2014 2:09 PM, "Matt Zabriskie" [email protected] wrote:

Can you give me an example of what you're trying to do with async
transforms?


Reply to this email directly or view it on GitHub
#19 (comment).

from axios.

nickdima avatar nickdima commented on April 17, 2024

I wanted to convert the data into another format and I was using some async API, but in the end I think doing it outside the request is better in this case.

from axios.

mzabriskie avatar mzabriskie commented on April 17, 2024

@nickdima I think that interceptors are probably what you are looking for. I have supporting interceptors on the road map (see #14).

from axios.

kentcdodds avatar kentcdodds commented on April 17, 2024

I remembered my use case better. We had data that had a slug and we needed to convert that to the actual value for the model, to get the values of the slugs, we needed to make a request for those. There was a race condition where the request for the data came back before the slug values request came back. This is why it was useful to have async transforms. Perhaps this could also be done with an interceptor though...?

from axios.

mzabriskie avatar mzabriskie commented on April 17, 2024

@kentcdodds yes, this is when you would want interceptors. Based on the Angular spec they are designed to handle async operations. Transformers are for mutating request/response data (JSON.stringify, JSON.parse, etc.), and for modifying headers. Interceptors are for any kind of pre processing on requests, and post processing on responses, either synchronously or asynchronously. With an interceptor you have access to the full config for the request, not just data, and headers as with transformers. This allows for global error handling, timing requests, authentication, session restoration, etc. In your case you could asynchronously fetch data from the server before the request was sent, then modify the data being sent in the original request with the response of the nested request.

from axios.

kentcdodds avatar kentcdodds commented on April 17, 2024

Awesome. Come to think of it, we may have switched over to an interceptor to accomplish what we were trying to do. Haha. Thanks for explaining that @mzabriskie!

from axios.

mzabriskie avatar mzabriskie commented on April 17, 2024

This is a duplicate and will be resolved with #14

from axios.

samuelcastro avatar samuelcastro commented on April 17, 2024

Hey @nickdima, I'm in the same situation here trying to parse responses converting String dates into moment.js object, how did you fix that? I've created a interceptor but its taking much time to parse it when we have a big response, did you a find a way to do that asynchronously?

from axios.

Related Issues (20)

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.