GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.62k stars 331 forks source link

Patch Requests #217

Closed demersus closed 7 years ago

demersus commented 7 years ago

Does this library support PATCH? router.patch() is undefined.

jeffposnick commented 7 years ago

It does not.

Could you explain a bit more about how you see sw-toolbox interacting with PATCH requests? It doesn't seem like one of the runtime caching strategies would be particularly appropriate for use with a PATCH.

demersus commented 7 years ago

I'm building an app that needs to run offline and place requests into a queue while a connection is not available. Some of these requests will be patch requests because the api is JSONAPI compliant. The goal is to queue the requests into indexeddb and replay them once a connection is available.

jeffposnick commented 7 years ago

sw-toolbox is good for implementing runtime caching strategies, but doesn't have any support for queueing and replaying failed requests.

There's nothing stopping you from mixing and matching your usage of sw-toolbox along with your own fetch handlers that implement custom behavior like what you describe. Just make sure that your fetch handler is added before sw-toolbox's routes have a chance to match a request. Inside your fetch handler, only call event.respondWith() if you're sure it's one of the requests you want to handle. So, something like:

self.addEventListener('fetch', event => {
  if (event.request.method === 'PATCH') {
    event.respondWith(
      // Your logic goes here.
    );
  }
});

// Use sw-toolbox to handle other runtime strategies here.
demersus commented 7 years ago

Thanks