{"id":15502731,"url":"https://github.com/j-siu/ng2-simple-api-lib","last_synced_at":"2026-05-03T04:36:59.726Z","repository":{"id":57359796,"uuid":"202825744","full_name":"J-Siu/ng2-simple-api-lib","owner":"J-Siu","description":"simple-api-client-ng2 is an Angular api service, which work with simple-api-express, an expressjs api handler. ","archived":false,"fork":false,"pushed_at":"2022-05-16T06:12:15.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-19T17:27:46.815Z","etag":null,"topics":["angular","api-client","service"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/J-Siu.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-08-17T02:32:40.000Z","updated_at":"2022-05-16T06:12:18.000Z","dependencies_parsed_at":"2022-09-06T21:41:36.860Z","dependency_job_id":null,"html_url":"https://github.com/J-Siu/ng2-simple-api-lib","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/J-Siu%2Fng2-simple-api-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Siu%2Fng2-simple-api-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Siu%2Fng2-simple-api-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Siu%2Fng2-simple-api-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J-Siu","download_url":"https://codeload.github.com/J-Siu/ng2-simple-api-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246077318,"owners_count":20719967,"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","api-client","service"],"created_at":"2024-10-02T09:10:53.474Z","updated_at":"2026-05-03T04:36:57.933Z","avatar_url":"https://github.com/J-Siu.png","language":"TypeScript","funding_links":["https://www.paypal.com/donate/?business=HZF49NM9D35SJ\u0026no_recurring=0\u0026currency_code=CAD"],"categories":[],"sub_categories":[],"readme":"# Angular Simple API Client [![Paypal donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/donate/?business=HZF49NM9D35SJ\u0026no_recurring=0\u0026currency_code=CAD)\n\n[simple-api-client-ng2](//github.com/J-Siu/ng2-simple-api-lib) is an Angular api service, which work with [simple-api-express](//github.com/J-Siu/simple-api-express), an ExpressJS api handler.\n\n\u003e __simple-api-client-ng2__ uses Angular CLI starting 8.2.0. New repository [github.com/J-Siu/ng2-simple-api-lib](//github.com/J-Siu/ng2-simple-api-lib/) contains both library and server example.\n\u003e\n\u003e Version \u003c 8.2.0 are in old repository [github.com/J-Siu/simple-api-client-ng2](//github.com/J-Siu/simple-api-client-ng2/).\n\n### Table Of Content\n\u003c!-- TOC --\u003e\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Module](#module)\n  - [Component](#component)\n- [API](#api)\n  - [SimpleApiClient.get](#simpleapiclientget)\n  - [SimpleApiClient.list](#simpleapiclientlist)\n  - [SimpleApiObj.call](#simpleapiobjcall)\n  - [SimpleApiObj.setErrorHandler](#simpleapiobjseterrorhandler)\n- [Error Handling](#error-handling)\n- [Example](#example)\n- [Repository](#repository)\n- [Contributors](#contributors)\n- [Changelog](#changelog)\n- [License](#license)\n\n\u003c!-- /TOC --\u003e\n\n### Install\n\n```sh\nnpm install simple-api-client-ng2\n```\n\n### Usage\n\n`simple-api-client-ng2` is implemented as Angular 2 injectable service name __SimpleApiClient__.\n\n#### Module\n\nAdd `SimpleApiClient` into module providers:\n\n```javascript\nimport { SimpleApiClient } from 'simple-api-client-ng2';\n\n@NgModule({\n  providers: [SimpleApiClient]\n})\n```\n\n#### Component\n\n```javascript\nimport {SimpleApiClient, SimpleApiObj} from 'simple-api-client-ng2';\n\nexport class ChildComponent implement OnInit {\n\n  apiObject: SimpleApiObj;\n\n  constructor(private api: SimpleApiClient) { }\n\n  ngOnInit() {\n    this.apiObject = this.api.get('/demo');\n\n    let reply = '';\n    this.apiObject.call(\n      'echo',\n      'This is a test',\n      r =\u003e this.reply = r);\n\n    console.log(this.reply);\n  }\n\n}\n```\n\n### API\n\n#### SimpleApiClient.get\n\n`SimpleApiClient.get(baseUrl: string = '/'): SimpleApiObj`\nwill return a SimpleApiObj configure with `baseUrl`.\nPrevious created SimpleApiObj will be returned if the same baseUrl is used.\n\n```javascript\n  this.apiObject = this.api.get('/demo');\n```\n\n#### SimpleApiClient.list\n\n`SimpleApiClient.list(): string[]` will return a string array containing the baseUrl of all SimpleApiObj created.\n\n#### SimpleApiObj.call\n\n`SimpleApiObj.call(method, params, callback, errorHandler)`\n\n- __method: string__ Name of api\n- __params: any__ Argument of api, can be basic type like string, number, or object\n- __callback: (result: any) =\u003e void__ Callback function for handling api result\n- __errorHandler: (error: any) =\u003e void = this.errorHandler__ Optional error handler to handle api call error\n\n#### SimpleApiObj.setErrorHandler\n\n`SimpleApiObj.setErrorHandler(handler: (any) =\u003e void)` replace SimpleApiObj default error handler with the specified one.\n\n### Error Handling\n\nFor detail example on error handling, please refer to [error.component.ts](https://github.com/J-Siu/ng2-simple-api-lib/blob/master/src/app/error.component.ts) contain in full example below.\n\n### Example\n\n```sh\n├── dist/\n│   ├── ng2-simple-api-lib/     // Compiled angular application\n│   └── simple-api-client-ng2/  // Compiled library\n├── projects/\n│   └── simple-api-client-ng2/  // Library source\n├── server/                     // Example server.\n└── src/\n    └── app/                    // Example app source\n```\n\n\u003e The example server is not an angular application. It is a nodejs application.\n\nYou will need Angular CLI to build the library and run the example.\n\n- Angular CLI: 8.2.2\n- Node : v10.10.0\n\n```sh\ngit clone https://github.com/J-Siu/ng2-simple-api-lib.git\ncd ng2-simple-api-lib\nnpm i\n```\n\nBuild the library:\n\n```sh\nng build simple-api-client-ng2\n```\n\nBuild the Angular app:\n\n```sh\nng build\n```\n\nRun the server:\n\n```sh\ncd server\nnode server.js\n```\n\nConnect your browser to http://localhost:4000 .\n\n### Repository\n\n- [ng2-simple-api-lib](https://github.com/J-Siu/ng2-simple-api-lib)\n\n### Contributors\n\n- [John Sing Dao Siu](https://github.com/J-Siu)\n\n### Changelog\n\n- 1.2.0\n  - Publish to NPM.\n- 1.2.1\n  - Fix Readme.md typo\n- 1.2.2\n  - Update package.json\n  - Update Readme.md\n- 8.2.0\n  - Support Angular 8.2.0\n  - Switch to Angular Cli for faster update.\n  - Include example\n- 8.2.1\n  - README.md clean up\n- 9.1.0\n  - Support Angular 9.1.0\n- 11.2.9\n  - Support Angular 11.2.9\n\n### License\n\nThe MIT License\n\nCopyright (c) 2021\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 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 Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-siu%2Fng2-simple-api-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj-siu%2Fng2-simple-api-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-siu%2Fng2-simple-api-lib/lists"}