{"id":20797681,"url":"https://github.com/beachmachine/angular-resource-factory","last_synced_at":"2025-07-11T08:10:54.426Z","repository":{"id":57179003,"uuid":"85866243","full_name":"beachmachine/angular-resource-factory","owner":"beachmachine","description":"A factory build upon $resource helping you to interact with RESTful APIs with advanced features as caches and data stores.","archived":false,"fork":false,"pushed_at":"2018-09-27T12:36:33.000Z","size":1112,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-18T08:04:08.091Z","etag":null,"topics":["angular","angularjs","resource","rest","restful"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beachmachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-22T19:09:39.000Z","updated_at":"2017-08-02T05:38:21.000Z","dependencies_parsed_at":"2022-09-09T19:00:52.074Z","dependency_job_id":null,"html_url":"https://github.com/beachmachine/angular-resource-factory","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fangular-resource-factory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fangular-resource-factory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fangular-resource-factory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fangular-resource-factory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beachmachine","download_url":"https://codeload.github.com/beachmachine/angular-resource-factory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243141238,"owners_count":20242819,"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","angularjs","resource","rest","restful"],"created_at":"2024-11-17T16:34:54.296Z","updated_at":"2025-03-12T02:12:57.843Z","avatar_url":"https://github.com/beachmachine.png","language":"JavaScript","readme":"[![Build Status](https://travis-ci.org/beachmachine/angular-resource-factory.svg?branch=master)](https://travis-ci.org/beachmachine/angular-resource-factory)\n\n# Angular ResourceFactory\n\nAngular ResourceFactory is an AngularJS library that extends the capabilities of ngResource in various ways. The main \nfeatures include a resource store for holding changes on resource instances and related resource instances to commit\nthem at once, and an advanced resource caching.\n\n**Note:** This library is for AngularJS 1.x only!\n\n\n## Dependencies\n\nAngular ResourceFactory depends on AngularJS 1.x.\n\n\n## Installation\n\n* Via `npm`: `npm install --save angular-resource-factory`\n* Via `git`: `git clone git@github.com:beachmachine/angular-resource-factory.git`\n\n\n## Examples\n\n### RESTful service definition\n\nIn the following example we assume a RESTful endpoint that gives us the total of results via the `count` attribute\nand the actual data in the `results` attribute in the list call. Each object has an ID on the `pk` attribute, holds\nits own URL on the `url` attribute and also has some dates as `creation_date` and `last_modification_date` that we\nwant to handle as Moment.js objects.\n\nTo make things a bit clearer, this is the list call result of the RESTful API endpoint:\n````json\n{\n  \"count\": 2,\n  \"results\": [\n    {\n      \"pk\": 1,\n      \"url\": \"http://example.api/member/1/\",\n      \"creation_date\": \"2017-01-11T06:00:00Z\",\n      \"last_modification_date\": \"2017-01-12T08:00:00Z\",\n      \"name\": \"Example Member 1\"\n    },\n    {\n      \"pk\": 2,\n      \"url\": \"http://example.api/member/2/\",\n      \"creation_date\": \"2017-01-11T06:00:00Z\",\n      \"last_modification_date\": \"2017-01-12T08:00:00Z\",\n      \"name\": \"Example Member 2\"\n    }\n  ]\n}\n````\n\nWhereas this is the result of a detail call:\n````json\n{\n  \"pk\": 2,\n  \"url\": \"http://example.api/member/2/\",\n  \"creation_date\": \"2017-01-11T06:00:00Z\",\n  \"last_modification_date\": \"2017-01-12T08:00:00Z\",\n  \"name\": \"Example Member 2\"\n}\n````\n\nOur service definition may look like this:\n````javascript\nvar module = angular.module('services');\n\nmodule.factory('MemberResourceService',\n    function (ResourceFactoryService) {\n        return ResourceFactoryService('MemberResourceService', 'http://example.api/member/:pk/', {\n            dataAttr: 'results',\n            queryTotalAttr: 'count',\n            pkAttr: 'pk',\n            urlAttr: 'url',\n\n            /**\n             * Converts the dates to moment objects.\n             * @param obj\n             * @return {*}\n             */\n            toInternal: function (obj) {\n                // no transformation needed if given object is false\n                if (!obj) {\n                    return obj;\n                }\n\n                obj.creation_date = obj.creation_date ? moment(obj.creation_date) : null;\n                obj.last_modification_date = obj.last_modification_date ? moment(obj.last_modification_date) : null;\n\n                return obj;\n            },\n\n            /**\n             * Converts the moment dates to strings.\n             * @param obj\n             * @return {*}\n             */\n            fromInternal: function (obj) {\n                // no transformation needed if given object is false\n                if (!obj) {\n                    return obj;\n                }\n\n                obj.creation_date = obj.creation_date ? moment(obj.creation_date).toJSON() : null;\n                obj.last_modification_date = obj.last_modification_date ? moment(obj.last_modification_date).toJSON() : null;\n\n                return obj;\n            }\n        });\n    }\n);\n````\n\n\n## Plunker\n\n* [Demo 1](https://embed.plnkr.co/JUZTVZyYcU58AaFGvlr4/): Simple demo that shows how to load data and how to clear the cache.\n\n\n## Contributions\n\n* Andreas Stocker \u003candreas@stocker.co.it\u003e, Main developer\n\n\n## License\n\nAngular ResourceFactory,\nCopyright 2016 Andreas Stocker,\nMIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\nrights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the\nSoftware.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\nWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\nOR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeachmachine%2Fangular-resource-factory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeachmachine%2Fangular-resource-factory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeachmachine%2Fangular-resource-factory/lists"}