npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-api-client-ng2

v11.2.9

Published

Angular simple api client service that work with simple-api-express

Downloads

3

Readme

simple-api-client-ng2 is an Angular api service, which work with simple-api-express, an ExpressJS api handler.

simple-api-client-ng2 uses Angular CLI starting 8.2.0. New repository github.com/J-Siu/ng2-simple-api-lib contains both library and server example.

Version < 8.2.0 are in old repository github.com/J-Siu/simple-api-client-ng2.

Install

npm install simple-api-client-ng2

Usage

simple-api-client-ng2 is implemented as Angular 2 injectable service name SimpleApiClient.

Module

Add SimpleApiClient into module providers:

import { SimpleApiClient } from 'simple-api-client-ng2';

@NgModule({
  providers: [SimpleApiClient]
})

Component

import {SimpleApiClient, SimpleApiObj} from 'simple-api-client-ng2';

export class ChildComponent implement OnInit {

  apiObject: SimpleApiObj;

  constructor(private api: SimpleApiClient) { }

  ngOnInit() {
    this.apiObject = this.api.get('/demo');

    let reply = '';
    this.apiObject.call(
      'echo',
      'This is a test',
      r => this.reply = r);

    console.log(this.reply);
  }

}

API

SimpleApiClient.get

SimpleApiClient.get(baseUrl: string = '/'): SimpleApiObj will return a SimpleApiObj configure with baseUrl. Previous created SimpleApiObj will be returned if the same baseUrl is used.

  this.apiObject = this.api.get('/demo');

SimpleApiClient.list

SimpleApiClient.list(): string[] will return a string array containing the baseUrl of all SimpleApiObj created.

SimpleApiObj.call

SimpleApiObj.call(method, params, callback, errorHandler)

  • method: string Name of api
  • params: any Argument of api, can be basic type like string, number, or object
  • callback: (result: any) => void Callback function for handling api result
  • errorHandler: (error: any) => void = this.errorHandler Optional error handler to handle api call error

SimpleApiObj.setErrorHandler

SimpleApiObj.setErrorHandler(handler: (any) => void) replace SimpleApiObj default error handler with the specified one.

Error Handling

For detail example on error handling, please refer to error.component.ts contain in full example below.

Example

├── dist/
│   ├── ng2-simple-api-lib/     // Compiled angular application
│   └── simple-api-client-ng2/  // Compiled library
├── projects/
│   └── simple-api-client-ng2/  // Library source
├── server/                     // Example server.
└── src/
    └── app/                    // Example app source

The example server is not an angular application. It is a nodejs application.

You will need Angular CLI to build the library and run the example.

  • Angular CLI: 8.2.2
  • Node : v10.10.0
git clone https://github.com/J-Siu/ng2-simple-api-lib.git
cd ng2-simple-api-lib
npm i

Build the library:

ng build simple-api-client-ng2

Build the Angular app:

ng build

Run the server:

cd server
node server.js

Connect your browser to http://localhost:4000 .

Repository

Contributors

Changelog

  • 1.2.0
    • Publish to NPM.
  • 1.2.1
    • Fix Readme.md typo
  • 1.2.2
    • Update package.json
    • Update Readme.md
  • 8.2.0
    • Support Angular 8.2.0
    • Switch to Angular Cli for faster update.
    • Include example
  • 8.2.1
    • README.md clean up
  • 9.1.0
    • Support Angular 9.1.0
  • 11.2.9
    • Support Angular 11.2.9

License

The MIT License

Copyright (c) 2021

Permission 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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE 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.