Code Monkey home page Code Monkey logo

Comments (14)

kuitos avatar kuitos commented on July 28, 2024 8

@brendanmatkin
Thanks for your valuable information!
As more than one person had asked for the post cacheable feature, we may need to provide a mechanism to make user can define the cacheable logic by himself.
I'm going to think about how to do that in the near feature, and you can make any suggestion at any time.

from axios-extensions.

kuitos avatar kuitos commented on July 28, 2024 1

POST requests are not supported, and I think to fetch data with POST request was not a good idea...

from axios-extensions.

brendanmatkin avatar brendanmatkin commented on July 28, 2024 1

For the sake of discussion:

Technically the HTTP/1.1 RFC document says that POST is a cacheable method: https://tools.ietf.org/html/rfc7231#section-4.2.3.
MDN also says it is cacheable if freshness information is included: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST

In my case I need to send data to be analyzed (as a big JSON) to the server in order to get a response (which can take several minutes to process) - I'd like to cache that response as long as the request body is the same. I don't mind having to manually forceUpdate, but it would be super nice to be able to cache the response to a POST.
It's also possible that this pattern shouldn't be a RESTful interface..

I guess it might be a big change though, since it looks like this library is really structured around GETs and the buildURL helper - how would we handle the POST body if we were to update this project, right?

Anyway I'd like to help but it's a bit over my head. If anyone can give me a few pointers, I can work on it and try to contribute. Thoughts?

from axios-extensions.

lkounadis avatar lkounadis commented on July 28, 2024 1

@kuitos have a look a cachios, it has a nice implementation of it. mostly due to being able to cache the post request/response with a custom key you want
Good work though!

from axios-extensions.

kuitos avatar kuitos commented on July 28, 2024

closed

from axios-extensions.

hongbo-miao avatar hongbo-miao commented on July 28, 2024

Hi @kuitos

I think sometimes it makes sense to cache POST requests.

One example I can find is

POST https://graph.microsoft.com/api/beta/me/getMailTips

{
    "EmailAddresses": [
        "[email protected]", 
        "[email protected]"
    ],
    "MailTipsOptions": "automaticReplies, mailboxFullStatus"
}

It returns Jack and Rose's mailtip.

BTW, thanks for brining us this library!

from axios-extensions.

kuitos avatar kuitos commented on July 28, 2024

This api was served by graphql?

from axios-extensions.

hongbo-miao avatar hongbo-miao commented on July 28, 2024

No, it is REST API. Sorry, forget the link. https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/user_getmailtips

from axios-extensions.

kuitos avatar kuitos commented on July 28, 2024

@hongbo-miao
Basically POST is not an idempotent operation in semantics. So caching for post request will not be provided imo. See https://stackoverflow.com/questions/626057/is-it-possible-to-cache-post-methods-in-http

from axios-extensions.

hongbo-miao avatar hongbo-miao commented on July 28, 2024

@kuitos got it, thank you for the info!

from axios-extensions.

brendanmatkin avatar brendanmatkin commented on July 28, 2024

@kuitos ok thanks! I'll chew on it.

For now I'm thinking (since it seems to be needed in only a few edge cases), that checking if the body has changed happens in the implementation (maybe using force-update), and axios-extensions just allows us to use POST as a method. (I guess this is probably what you mean by "define the caceable logic by himself").

This would probably be way easier to build but might lead to some confusion when things are automatically caching even though something has changed... maybe we add another option to flag it as manual caching logic?

from axios-extensions.

abhipanda avatar abhipanda commented on July 28, 2024

@kuitos I feel a generic library like "axios-extensions" should cater to all the methods that axios supports without introducing any subjective presumptions about any methods. It should be on the user to determine which rule of theory they follow. It should let the user choose ingredients of the hash e.g. query, params, body, headers etc. You could just have "cache":true and additional hashing inputs from user.

Doing that would give this library a more generic, free from any assumptions.

from axios-extensions.

gustavo-h-freitas avatar gustavo-h-freitas commented on July 28, 2024

POST requests are not supported, and I think to fetch data with POST request was not a good idea...

I've created an package at npm to cache post and get request, just look for axios-post-cache

from axios-extensions.

gongjianh avatar gongjianh commented on July 28, 2024

@brendanmatkin Thanks for your valuable information! As more than one person had asked for the post cacheable feature, we may need to provide a mechanism to make user can define the cacheable logic by himself. I'm going to think about how to do that in the near feature, and you can make any suggestion at any time.

Excuse me, has this function been added?

from axios-extensions.

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.