{"id":15397287,"url":"https://github.com/bloomca/pump-requests","last_synced_at":"2025-09-01T13:42:28.184Z","repository":{"id":57332046,"uuid":"93572212","full_name":"Bloomca/pump-requests","owner":"Bloomca","description":"Small library to treat request over collections as independent requests for a single resource","archived":false,"fork":false,"pushed_at":"2017-06-17T06:18:23.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T10:48:23.314Z","etag":null,"topics":["gathering","requests","separation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bloomca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-06T23:38:08.000Z","updated_at":"2017-12-06T22:53:32.000Z","dependencies_parsed_at":"2022-09-02T17:14:55.951Z","dependency_job_id":null,"html_url":"https://github.com/Bloomca/pump-requests","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bloomca%2Fpump-requests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bloomca%2Fpump-requests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bloomca%2Fpump-requests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bloomca%2Fpump-requests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bloomca","download_url":"https://codeload.github.com/Bloomca/pump-requests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318721,"owners_count":20919483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gathering","requests","separation"],"created_at":"2024-10-01T15:36:54.161Z","updated_at":"2025-04-05T09:43:52.447Z","avatar_url":"https://github.com/Bloomca.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pump-requests\n\n[![Build Status](https://travis-ci.org/Bloomca/pump-requests.svg?branch=master)](https://travis-ci.org/Bloomca/pump-requests)\n[![npm version](https://badge.fury.io/js/pump-requests.svg)](https://badge.fury.io/js/pump-requests)\n\nLet's say we have an endpoint, which receives list of ids as a parameter to check their status (for example, list of favourites). However, we would like to call status of each item individually (think about React component, which will get all needed information for a component). This library does exactly one thing – it allows you to treat such requests as they were requests to check status of a single item. They are added into internal data structures, and each addition triggers debounced timer, so after defined time of silence it will invoke given function, passing list of all ids it collected.\n\n```javascript\nimport pumpRequests from 'pump-requests';\nimport api from '../api';\n\n// you can pass this function wherever you want\n// if you use redux, you can pass it to the\n// middleware\nconst checkFavourite = pumpRequests(ids =\u003e {\n  return api.get('/favourites', ids);\n  // for instance, { 5: 'some', 10: 'another' }\n});\n\ncheckFavourite(5).then(val =\u003e console.log(val)); // 'some'\ncheckFavourite(10).then(val =\u003e console.log(val)); // 'another'\n```\n\n## API\n\n```javascript\nimport pumpRequest from 'pump-requests';\n\nconst checkFavourite = pumpRequest(\n  // this function will be invoked with array of parameters,\n  // with which `checkFavourite` was called by individual items\n  fn: (ids) =\u003e api.get(...),\n  {\n    // debounce time – after which period of silence we will call fn\n    // default value is 50\n    time: 100,\n    \n    // function to get information for specific call\n    // results – data from fn\n    // id – parameter with which you called `checkFavourite`\n    //\n    // default value is (results, id) =\u003e results[id],\n    // so, it means you have to pass string as an id, and\n    // resolve object from fn with ids as keys\n    parseParams: (results, id) =\u003e ...\n  }\n);\n```\n\nThere is nothing more! The idea for the library was born when I was struggling trying to prefetch different favourites in several places, and they clashed – I feel that treating them as independent single requests with single responsibility is a right way to go.\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbloomca%2Fpump-requests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbloomca%2Fpump-requests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbloomca%2Fpump-requests/lists"}