{"id":21434798,"url":"https://github.com/zivl/restful-js","last_synced_at":"2025-08-11T20:13:53.126Z","repository":{"id":57355034,"uuid":"67859546","full_name":"zivl/restful-js","owner":"zivl","description":"Simple and generic JavaScript class to handle REST API calls","archived":false,"fork":false,"pushed_at":"2017-11-08T13:43:08.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-27T19:54:48.537Z","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/zivl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-09-10T08:19:13.000Z","updated_at":"2016-11-08T08:43:08.000Z","dependencies_parsed_at":"2022-08-28T11:20:31.756Z","dependency_job_id":null,"html_url":"https://github.com/zivl/restful-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zivl/restful-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Frestful-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Frestful-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Frestful-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Frestful-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zivl","download_url":"https://codeload.github.com/zivl/restful-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Frestful-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269948877,"owners_count":24501827,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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-22T23:40:42.623Z","updated_at":"2025-08-11T20:13:53.076Z","avatar_url":"https://github.com/zivl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Restful JS\n[![Build Status](https://travis-ci.org/zivl/restful-js.svg?branch=master)](https://travis-ci.org/zivl/restful-js)\n[![npm version](https://badge.fury.io/js/restful-js.svg)](https://badge.fury.io/js/restful-js)\n\nA simple and generic way to handle RESTful API calls in your JavaScript application.\u003cbr\u003e\nThere are many libraries and utilities classes which provide RESTful implementation in JavaScript to handle API calls to server. Unfortunately, those other solutions, as good as they are, not always suits for everyone. Sometimes, the willing to do everything, just makes it more complex and harder to use. \u003cbr\u003e\nThis `restful-js` solution, keeps stuff the most simple there is, and exposes a nice and easy interface for use in your app.\nIn case of customized logic, there are some hook methods you can override\n\n### Install\n```\nnpm install restful-js --save\n```\n\n### How to use\n***`fetch(url, options)`*** or ***`get(url, options)`***\u003cbr\u003e\nSends ***HTTP GET*** request with the following parameters:\u003cbr\u003e\n`url: String` - the URL resource.\u003cbr\u003e\n`options: Object` - All of the `ajax` options you would like to provide.\n\n***`post(url, data, options)`***\u003cbr\u003e\nSends ***HTTP POST*** request with the following parameters:\u003cbr\u003e\n`url: String` - the URL resource.\u003cbr\u003e\n`data: Any` - The data you would like to send to the server.\u003cbr\u003e\n`options: Object` - All of the `ajax` options you would like to provide.\n\n***`put(url, data, options)`***\u003cbr\u003e\nSends ***HTTP PUT*** request with the following parameters:\u003cbr\u003e\n`url: String` - the URL resource.\u003cbr\u003e\n`data: Any` - The data you would like to send to the server.\u003cbr\u003e\n`options: Object` - All of the `ajax` options you would like to provide.\n\n***`destroy(url, options)`***\u003cbr\u003e\nSends ***HTTP DELETE*** request with the following parameters:\u003cbr\u003e\n`url: String` - the URL resource.\u003cbr\u003e\n`options: Object` - All of the `ajax` options you would like to provide.\n\n### Different ways to use\n\n##### As a Singelton\nBy default, an instance of the restful-js object is exported and ready to use.\u003cbr\u003e\nFor example:\u003cbr\u003e\n```\nimport RestApi from 'restful-js';\n// later on...\nRestApi.fetch('some/url/resource').then(response =\u003e { /* handle response */ });\n\n```\n\n##### As a Class\nYou may also get a class and instantiate it yourself and manage it's life-cycle. \u003cbr\u003e\nFor example:\u003cbr\u003e\n```\nimport {RestfulAPI} from 'restful-js';\n// later on...\nlet restfulAPI = new RestfulAPI();\nrestfulAPI.fetch(`${baseUrl}/users`).then(response =\u003e { /* handle response */ });\n```\n\n##### Add event handlers\nYou may instantiate a class and give different handlers for XHR events. \u003cbr\u003e\nFor example:\u003cbr\u003e\n```\nimport {RestfulAPI} from 'restful-js';\n// later on...\nlet restfulAPI = new RestfulAPI({\n\terrorResponseHandler: (xhr, textStatus, errorThrown) =\u003e {...}\n\tajaxStartHandler: () =\u003e {...},\n\tajaxStopHandler: () =\u003e {...}\n});\n```\n\n##### Inherit and add you own customization\nYou can easily customize some behavioural stuff by inheriting from the exported `RestfulAPI` and add your own logic.\n\u003cbr\u003e\nFor example:\u003cbr\u003e\n```\nimport {RestfulAPI} from 'restful-js';\n\nclass MyRestfulAPI extends RestfulAPI {\n    applySecurity(options, data){\n        // add some security logic\n    }\n}\n```\n\n##### Get a jQuery reference\nYou may get a `jQuery` reference for your own usage and event handling\n\u003cbr\u003e\nFor example:\u003cbr\u003e\n```\nimport {RestfulAPI} from 'restful-js';\n\nconst restfulAPI = new RestAPIUtil();\n\n// jQuery binary transport to download files through XHR\nrestfulAPI.$.ajaxTransport('+binary', () =\u003e {...})\n\n```\n\n### Having some trouble? Have an issue?\nFor bugs and issues, please use the [issues](https://github.com/zivl/restful-js/issues) page.\n\n\n### Road map\n* Add support for more HTTP methods\n* Remove the need of `jQuery.ajax` and use the global `fetch` way! (waiting for full browser support)\n\n\n### Contribute\nSure! just fork this repository and join in!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzivl%2Frestful-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzivl%2Frestful-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzivl%2Frestful-js/lists"}