{"id":21031308,"url":"https://github.com/workable/request","last_synced_at":"2026-04-28T10:31:59.763Z","repository":{"id":40728188,"uuid":"240235121","full_name":"Workable/request","owner":"Workable","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-19T10:23:37.000Z","size":2050,"stargazers_count":0,"open_issues_count":17,"forks_count":2,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-10-19T20:53:34.848Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/Workable.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-13T10:36:18.000Z","updated_at":"2025-10-19T10:23:41.000Z","dependencies_parsed_at":"2025-01-20T15:33:40.014Z","dependency_job_id":null,"html_url":"https://github.com/Workable/request","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Workable/request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Frequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Frequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Frequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Frequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Workable","download_url":"https://codeload.github.com/Workable/request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Frequest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32377076,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T09:24:15.638Z","status":"ssl_error","status_checked_at":"2026-04-28T09:24:15.071Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-19T12:27:11.025Z","updated_at":"2026-04-28T10:31:59.746Z","avatar_url":"https://github.com/Workable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# request\n\nHTTP client that uses the native fetch.\nRequest is based on middlewares in order to extend the default fetch functionality.\n\n## Installing\n\nUsing npm:\n\n```\n$ npm install @workablehr/request\n```\n\n## Basic usage\n\n```javascript\nimport request from \"@workablehr/request\";\n\nconst promise = request(\"resource.com\"); // submits a get request to 'resource.com'\n\npromise\n  .then(reponse =\u003e {\n    console.log(\"reponse\", reponse);\n  })\n  .catch(error =\u003e {\n    console.error(\"error\", error);\n  });\n```\n\nRequest will resolve the promise if the response status is between 200 and 299. Otherwise, it will reject the promise.\nIf the promise resolved successfully, it will return the JSON content of the response.\nIf the promise rejected, it will return an error containing the response and an XHRHandler.\n\n## XHRHandler\n\nXHRHandler triggers callbacks according to http response rules.\n\n### Example\n\n```javascript\nXHRHandler.init(response).catch(error =\u003e\n  error.asyncHandler.then(handler =\u003e\n    handler\n      .when(400, () =\u003e \"doSomething\")\n      .whenNot(401, () =\u003e \"doSomething\")\n      .otherwise(() =\u003e \"doSomething\")\n      .always(() =\u003e \"doSomething\")\n      .handle()\n  )\n);\n```\n\n## Middlewares\n\n- withAbort\n- withCache\n- withShortcuts\n- withBgSync\n\nMiddleware is an easy way to extend the basic functionality of the request.\nFor example, if you would like to create a request that can be aborted, you could merely do:\n\n```javascript\nimport basicRequest, { withAbort } from \"@workablehr/request\";\nconst request = withAbort(basicRequest);\nconst promise = request(\"resource.com\", {\n  method: \"POST\",\n  body: JSON.stringify({ data })\n});\npromise.abort();\n```\n\nOr if you would like to use the shortcut request.post(), you could:\n\n```javascript\nimport basicRequest, { withAbort, withShortcuts } from \"@workablehr/request\";\nconst request = withShortcuts(withAbort(basicRequest));\nconst promise = request.post(\"resource.com\", { data });\npromise.abort();\n```\n\nYou can find more information for each middleware on the corresponding file.\n\n### withAbort\n\nInjects an abort function in the request promise.\n\n### withCache\n\nCaches a request in the indexed DB.\n\n### withShortcuts\n\nExtends the request method with post/put/del methods. \n\n### withBgSync\n\nSends the request to the service worker in order to perform it when the device is back online.\n\n⚠️ It needs an extra handling in the service worker side, in order to cache the request with the 'bgSync: 1' header.\n\n### Custom middleware\n\nA middleware is nothing more than a simple function that accepts request method and returns the extended request.\n\n```javascript\nimport basicRequest from \"@workablehr/request\";\n\nconst withRequestLogger = request =\u003e {\n  return (url, params) =\u003e {\n    console.log(\"start request\", url);\n    request(url, params).then(response =\u003e {\n      console.log(\"successfully request\", url);\n      return response;\n    });\n  };\n};\n\nconst request = withRequestLogger(basicRequest);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkable%2Frequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkable%2Frequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkable%2Frequest/lists"}