{"id":21815302,"url":"https://github.com/galvao/jhrw","last_synced_at":"2025-10-26T00:43:52.056Z","repository":{"id":143749464,"uuid":"100898918","full_name":"galvao/JHRW","owner":"galvao","description":"A wrapper for so-called \"AJAX\" Requests","archived":false,"fork":false,"pushed_at":"2020-04-15T08:29:44.000Z","size":280,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T23:13:26.428Z","etag":null,"topics":["ajax","javascript","wrapper","xmlhttprequest-wrapper"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/galvao.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","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}},"created_at":"2017-08-21T01:09:57.000Z","updated_at":"2020-04-15T08:28:45.000Z","dependencies_parsed_at":"2023-05-24T09:15:33.438Z","dependency_job_id":null,"html_url":"https://github.com/galvao/JHRW","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galvao%2FJHRW","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galvao%2FJHRW/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galvao%2FJHRW/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galvao%2FJHRW/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galvao","download_url":"https://codeload.github.com/galvao/JHRW/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244776273,"owners_count":20508503,"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":["ajax","javascript","wrapper","xmlhttprequest-wrapper"],"created_at":"2024-11-27T15:17:31.695Z","updated_at":"2025-10-26T00:43:51.969Z","avatar_url":"https://github.com/galvao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"media/logo.png\" width=\"200\"\u003e\n\u003c/p\u003e\n\n# JHRW - JavaScript HTTP Request Wrapper\nA wrapper for so-called \"AJAX\" Requests\n\n## Goals\nI've made JHRW to:\n\n* Advance my JavaScript skills;\n* Improve/Simplify the usage of the [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) object by:\n    * Adding default values to what's undefined;\n    * Adding additional Error checking and clarification;\n    * Adding interesting, simplified, feature, such as timeouts and retries.\n\n## Documentation\n```JavaScript\nObject JHRW(String base, String urlPath [, Boolean lazyExecution = false [, Boolean bypassCache = false]]);\n```\n\n### Parameters\n* `String base` - The request's base URL\n* `String urlPath` - The request's endpoint\n* `Boolean lazyExecution`(optional) - If the request should be initialized and sent right after instantiation. Default: false\n* `Boolean bypassCache`(optional) - If the request URL should have a timed parameter added in order to bypass cache. Default: false\n\n### Throws\n* A `ReferenceError`\n    * If there's no JHRWHandler function defined.\n* A `Error`\n\t* if the base parameter is `undefined`\n\t* if the urlPath parameter is `undefined`\n* A `TypeError`\n\t* if the base parameter is not a `String`\n\t* if the urlPath parameter is not a `String`\n\t* if the lazyExecution parameter is not a `Boolean`\n\t* if the bypassCache parameter is not a `Boolean`\n\n\n### Returns\nAn Object containing:\n\n#### Properties\n* `Object request` - The native [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) Object\n* `Object config` - The configuration Object\n\t* `String URI` - The request's target\n\t* `Boolean asynchronous` - If the request should be asynchronous\n\t* `String verb` - The HTTP verb\n\t* `Mixed data` - Data to be sent along with the request\n\t* `Object requestHeaders` - HTTP headers for the request\n\t* `String responseType` - Expected MIME type of the response\n\t* `Object handlers` - The functions to handle the request\n\t* `Number attempts` - # of attempts to retry if the request fails\n\t* `Number attemptInterval` - Interval between attempts, **in seconds**.\n\t* `Number timeout` - The timeout, **in seconds**, for the request - after which it should be retried.\n\t* `Function postTimeout`: The function to be executed if the request times out.\n\t* `Number timer` - The [timer](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval) that controls the retry process.\n\n##### Static Properties\n* `Array JHRW.availableHandlers`: The types of handlers that can be [re-]defined.\n* `String JHRW.handlerList`: Convenience property to be shown in error messages.\n\n#### Methods\n##### configure\n```JavaScript\nvoid configure(Object configureObject);\n```\nOverwrites one or more configuration options (see the config object above)\n\n##### init\n```JavaScript\nvoid init();\n```\nInitializes the request: Sets the expected response MIME Type; Sets the handlers as listeners; Opens the request; Sets the request's headers.\n\n##### send\n```JavaScript\nvoid send();\n```\nSends the request, including data, if available.\n\n##### end\n```JavaScript\nvoid end();\n```\n\nEnds the request. Useful if you wish for JHRW to stop retrying on success.\n\n### Basic Usage\n```JavaScript\ntry {\n\tvar obj = new JHRW('http://localhost', /foo.php', true);\n} catch (Error e) {\n\t// Do something\n}\n```\nor\n\n```JavaScript\ntry {\n\tvar req = new JHRW('http://localhost', 'foo.php');\n\n\ttry {\n        req.init();\n\t} catch (ReferenceError e) {\n        // Do something\n    }\n\n    req.send();\n} catch (Error e) {\n    // Do something\n}\n```\n\nFor a more advanced usage example see [the testing page](src/example/requestTester.html).\n\n## Credits\n\n* Developed by @galvao.\n* Logo font: [Neutra Text Bold](http://fontsgeek.com/fonts/Neutra-Text-Bold)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalvao%2Fjhrw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgalvao%2Fjhrw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalvao%2Fjhrw/lists"}