{"id":18435891,"url":"https://github.com/darekf77/ng2-rest","last_synced_at":"2025-04-07T20:32:28.873Z","repository":{"id":56493670,"uuid":"58720806","full_name":"darekf77/ng2-rest","owner":"darekf77","description":"Isomorphic, simple, robust REST API library for Browser and NodeJS, ( ts / js ) apps ","archived":false,"fork":false,"pushed_at":"2024-05-22T04:37:49.000Z","size":9748,"stargazers_count":26,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-22T12:39:43.813Z","etag":null,"topics":["angular-httpclient-alternative","angular-rest","isomorphic","jsonp","nodejs-library","react-rest","request-cancellation","rest","rest-api","rxjs-observables","vue-rest"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darekf77.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-05-13T08:59:37.000Z","updated_at":"2024-06-01T18:18:35.117Z","dependencies_parsed_at":"2023-02-10T10:30:31.413Z","dependency_job_id":"b166324c-8e60-417b-8316-eb7cff6ff3c6","html_url":"https://github.com/darekf77/ng2-rest","commit_stats":{"total_commits":824,"total_committers":11,"mean_commits":74.9090909090909,"dds":0.4016990291262136,"last_synced_commit":"afbe27e6dce0dcc8960ab271fb8c2bb8a08a3b94"},"previous_names":[],"tags_count":304,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darekf77%2Fng2-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darekf77%2Fng2-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darekf77%2Fng2-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darekf77%2Fng2-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darekf77","download_url":"https://codeload.github.com/darekf77/ng2-rest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247673025,"owners_count":20977056,"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-httpclient-alternative","angular-rest","isomorphic","jsonp","nodejs-library","react-rest","request-cancellation","rest","rest-api","rxjs-observables","vue-rest"],"created_at":"2024-11-06T06:09:35.944Z","updated_at":"2025-04-07T20:32:23.914Z","avatar_url":"https://github.com/darekf77.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## ng2-rest ##\n\nRobust isomorphic REST framework for browser (Angular, React etc.) and backend (NodeJS) JavaScript/TypeScript apps.\n\nFeatures:\n- Compatible with Angular (2+) (newest 13,14 also...) , React, Vue , NodeJS (works everywhere)\n- Compatible with RxJS operators (exhaustMap, switchMap, request cancelation etc.)\n- Based on [axios](https://axios-http.com/) =\u003e excellent alternative to  Angular's [HttpClient](https://angular.io/api/common/http/HttpClient)\n- JSONP api request handling\n- Transfer class instance from server to client and back\n- Elegant way of dealing with REST api ( *similar to ExpressJS routes definitions* )\n\n(more documentation soon... )\n\nTo install this package run:\n\n    npm install ng2-rest --save\n\nImport Resource class:\n```ts\nimport { Resource } from 'ng2-rest/browser';\n```\n\nResource\n========\n\nFit you existing API (not only REST) into new fluent objects with **Resource** \n class observables. Use power of **async** in new angular templates;\n\n**template.html**  \n```html\nUsers:\n\u003cul   *ngIf=\"model.allUsers() | async; else loader; let users\" \u003e\n\n  \u003cli  *ngFor=\"let user of users\"\u003e \n  \t\t{{user.id}} {{user.fullName()}} \n\t\t  \u003cbr\u003e\n\t\t\u003cinput type=\"name\" [(NgModel)]=\"user.name\" \u003e\n\t\t\u003cbutton (click)=\"model.update(user)\" \u003e Update \u003c/button\u003e\n  \u003c/li\u003e\n\n\u003c/ul\u003e\n\n\u003cng-template #loader\u003e loading users...  \u003c/ng-template\u003e\n\n```\n**component.ts**\n```ts\nclass User {\n\tname: string;\n\tsurname: string;\n\tid: number;\n\n\tfullName() {\n\t\treturn `Surname: ${this.surname}, Name: ${this.name}`;\n\t}\n}\n\n// Express.js style url endpoint model\n// you can ommit \"\u003cUser\u003e\" part is you don't wanna see response interface\n// also you can ommit third argument \",User\" is you don't wanna\n// map response object to User class objects\nconst rest = Resource.create\u003cUser\u003e(\"http://yourbackend.com/api\",\"users/:id\",{'':User} )\n\nclass UserComponent {\n\n   // Prepare your beautiful interface\n    model = {\n\t allUsers: () =\u003e rest.model()\n\t\t .array\n\t\t .get()\n\t\t .observable // Observable resposne (useful for Angular 2+ html templates)\n     .pipe( map({ body } =\u003e body.json) ) // get all users, body.json =\u003e User[] \n\n\t userBy: (id) =\u003e rest.model({id})\n\t\t .get() // Promise response by default\n\t\t .then({ body } =\u003e console.log(body.json)) // get user by id,  body.json =\u003e User\n\n\t update: async (user:User) =\u003e{\n\t\t try {\n\t\t\tawait rest.model({id:user.id}).put(user) // Promise response by default\n\n\t\t\talert('Update sucess')\n\t\t } catch(e) {\n\t\t\talert(e)\n\t\t }\t\n\t \t}\n    }\n\n\tconstructor() { }\n\n}\n```\n\nSpecification\n============\nExample **UrlParams[]** :\n `[ { sort: true },{ filter: 'id,5' }, { filter: 'name,test' } ]` \n \n \n| Name | Parameters  | Description |\n| :---: | --- | ---: |\n| **.array.** | get,post,put,head,delete,jsonp |  for everything, but with arrays |\n| **get** | `UrlParams[] ` |   get model by parameters  |\n| **post** | `model, UrlParams[] ` |   post object model  |\n| **put** | `model, UrlParams[]` |   put object model |\n| **head** | `model, UrlParams[]` |   get head for model  |\n| **delete** | `UrlParams[]` |   remove object by params |\n| **jsonp** | `UrlParams[]` |   get jsonp data |\n\n\n\n# Production mode\n===\nNice things to do in production mode:\n\n**1. Disable warnings.**\n\nIf you don't wanna see warning, disable it like this:\n```ts\nif (environment.production) {\n  Resource.enableWarnings = false;\n}\n```\n\n# Angular 2+ ngZone\nIf you are using Angular 2+ you need to do this in your root **app.component**:\n```ts\nconstructor(zone:NgZone) {\n    Resource.initAngularNgZone(zone)\n}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarekf77%2Fng2-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarekf77%2Fng2-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarekf77%2Fng2-rest/lists"}