{"id":20919600,"url":"https://github.com/siddarthvader/angular-httpshooter","last_synced_at":"2025-03-12T23:48:51.254Z","repository":{"id":57178529,"uuid":"78180742","full_name":"siddarthvader/angular-httpshooter","owner":"siddarthvader","description":"An angular js factory which shoots http calls asynchronously.","archived":false,"fork":false,"pushed_at":"2018-02-13T16:03:51.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-18T19:08:51.951Z","etag":null,"topics":["angular","asynchronous","factory","http","promise"],"latest_commit_sha":null,"homepage":"","language":null,"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/siddarthvader.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-06T06:31:36.000Z","updated_at":"2018-02-13T16:00:55.000Z","dependencies_parsed_at":"2022-09-11T07:01:17.310Z","dependency_job_id":null,"html_url":"https://github.com/siddarthvader/angular-httpshooter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siddarthvader%2Fangular-httpshooter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siddarthvader%2Fangular-httpshooter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siddarthvader%2Fangular-httpshooter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siddarthvader%2Fangular-httpshooter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/siddarthvader","download_url":"https://codeload.github.com/siddarthvader/angular-httpshooter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243312923,"owners_count":20271167,"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":["angular","asynchronous","factory","http","promise"],"created_at":"2024-11-18T17:08:02.431Z","updated_at":"2025-03-12T23:48:51.233Z","avatar_url":"https://github.com/siddarthvader.png","language":null,"readme":"# Angular-httpshooter\n\u003e A factory written in angular 1.0+ which makes/shoots all http calls collectively asynchronously.\n\nAngular-httpshooter makes all your api calls asynchronous, idea behind it to make the connection between server and client single threaded, it means shooting only one call at a point of time and wait for the response from server to launch the next call.\n\n\u003e It blocks duplicate calls on the basis or either `url` or `data`, you can configure it according to your need.\n\nIt is based on `promise` chaining, it maintains a `queue` and push every call into it and then treat them on the basis of `FIFO`. it makes a promise for every `http` call and `reject`/`resolve` promise on the basis of response from server;\n\n\u003e Angular-httpshooter is here to provide enhanced support to maintain ACID property of DB.\n\nAlmost all new databases handle it on their level and serialize read/write calls using lock-based protocols and other measures, but it is always preferred that client handles the concurrency on its level.\n\n\u003e\u003e NOTE: it will only matches the calls which are yet to take place, past calls are removed from queue as soon as the server returns response.\n\n\n\u003e ![Example network panel](http://i.imgur.com/7i9FSkZ.png)\n\n\n\n## Features\n\n* One api/server call in action at one point of time.\n* it blocks duplicate server calls which generally happens when user press some button twice, read options for more details.\n* 'timeout' defines the max-time wait limit, it server does not respond before timeout limit, it rejects the promise and you will get 599 status in error block.\n* it releases two events on $rootScope `HTTP_CALL_STARTED` and `HTTP_CALL_STOPPED`, also sends config objects with events, you can catch this event and do many things. e.g. show loader or block UI from interaction.\n\n\n## Use Angular-httpshooter in your webapp\n\ninstall using npm\n```bash\nnpm install angular-httpshooter --save\n```\n\ninstall using bower\n```bash\nbower install angular-httpshooter media-all --save\n```\n\nclone the git repo\n\n```bash\ngit clone https://github.com/siddarthvader/angular-httpshooter.github\n```\n\nOnce you have downloded the package you will have to inject the dependency in your angular app.\n\nIn your Module\n````bash\n    app.module('angularApp',['angular-httpshooter']);\n````\n\nIn your Controller\n````bash\n    app.controller('appCtrl',['$httpshooter',function($httpshooter){\n\n        $httpshooter.queue({\n            method:'POST',\n            url:'http://example.com/postData',\n            data:data,\n            headers:headers \n        },timeout).then(function(data){\n            // if server returns success response\n            console.log(data);// will be main response returned from server, stripped of all other data\n        },function(data){\n            // if server returns error response\n        })\n\n    }]);\n````\n\nYes it is as simple as this.\n\n\n\n## Options\n\nHere are defaults values and possible values that can be passed to the factory for further processing.\n\n````bash\n| Property  |        Acceptable options       | Default options |\n|-----------|---------------------------------|-----------------|\n|  Method   |  get,post,delete,head,put,patch |        none     |\n|  url      |            \u003cstring\u003e             |        none     |\n|  data     |            \u003cobject\u003e             |        none     |\n|  headers  |            \u003cobject\u003e             |        none     |\n|  timeout  |       time in miliseconds       |     36000ms     |\n\n````\n\n## Events\n \n\n ````bash\n       $rootScope.$on('HTTP_CALL_STARTED', function (event,data) {\n            console.log(data.url)  // url of http call in action\n            console.log(data.data) // data of http call\n            console.log(data.headers) // headers of http call\n\n            // basically you get whole config object in here, including a promise\n            // you can start a loader here, or freeze UI or can do anything\n        });\n\n        $rootScope.$on('HTTP_CALL_STOPPED', function (event,data) {\n            // same data as above event\n\n            // you can stop a loader here, or enable submit button or anything else\n        });\n\n\n ````\n\n\n## Customization\n\nHere are the default values of params used in factory, you can configure them, like this:\n\n````bash\napp.config(function(shootConfig) {\n  angular.extend(shootConfig, {\n     defaultTimeOut:36000 // miliseconds\n     blockDuplicateCalls: true,\n     compareDuplicateParam:{\n        url:true,\n        data:false\n    }\n  });\n})\n````\n\n* **defaultTimeOut** : default value 36000ms, you can change it if you want to.\n\n* **blockDuplicateCalls** : default value `true`, change if you want to allow all calls to reach server.\n\n* **compareDuplicateParam.url** : default value `true`, if `true` factory matches the calls on the basis of  `url` string.\n\n* **compareDuplicateParam.data** : default value `false`, if `true` factory matches the calls on the basis on `data` object\n\n\n## Licence\n\nMIT\n\n### Feel free to fork or report issues, I am here to help. \\m/","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiddarthvader%2Fangular-httpshooter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsiddarthvader%2Fangular-httpshooter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiddarthvader%2Fangular-httpshooter/lists"}