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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-api-gateway-client

v0.7.0

Published

AWS API Gateway Client for Angular

Readme

ngx-api-gateway-client Build Status

AWS API Gateway Client for Angular

This library has a peer dependency on aws-sdk, so make sure to add that dependency to your project.

Install

$ npm install --save ngx-api-gateway-client

Usage

Configuration

In order to configure the AWSHttpModule, you have to provide a factory function that returns the configuration object.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AWSHttpModule } from 'ngx-api-gateway-client';

import { AppComponent } from './app.component';

export function awsHttpConfigFactory() {
	return {
		region: 'eu-west-1',
		apiKey: 'LwCPjpqye59hgONbe6IrD6VK5HDpGrVJ4fhE2Qmq',
		baseUrl: 'https://apiId.execute-api.eu-west-1.amazonaws.com/v1'
	};
}

@NgModule({
	imports: [
		BrowserModule,
		AWSHttpModule.forRoot(awsHttpConfigFactory)
	],
	declarations: [
		AppComponent
	],
	bootstrap: [
		AppComponent
	]
})
export class AppModule { }

Only the region property in the configuration object is mandatory.

HTTP requests

The way this module works is by configuring an HTTP interceptor which handles everything for you. If you use a baseUrl, you should use the AWSHttpClient, if not, you can just use the Angular HttpClient.

import { Component } from '@angular/core';
import { AWSHttpService, AWSHttpClient } from 'ngx-api-gateway-client';

@Component({
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.css']
})
export class AppComponent {

	constructor(
		private http: AWSHttpClient,
		private awsHttpService: AWSHttpService
	) { }

	onSubmit() {
		this.http.post('/login', {username: 'foo', password: 'bar'})
			.switchMap((result: any) => {
				// Store the login result for refreshing purposes
				window.localStorage.setItem('data', JSON.stringify(data));

				// We get temporary credentials back from the API, you can simply pass them through the the service and it will be taken care of automatically
				return this.awsHttpService.setCognitoCredentials({
					Token: result.Token,
					IdentityId: result.IdentityId
				});
			})
			.subscribe(() => {
				// Navigate to the home page
			});
	}
}

After the authentication request, we call the AWSHttpService.setCognitoCredentials which will handle the token exchange for you.

Refresh

A refreshing mechanism is built-in. However, because the library is not aware of the API endpoints that should be used or what data is returned, we have to provide some extra functions.

The AWSHttpService.refresh method accepts a function which returns a HttpRequest object which determines which endpoint should be made in order to refresh the token. Whenever the current token expires, that function is called and the HttpRequest is executed.

Because the library is not aware of what the response of the refresh request looks like, a second function has to be provided in the AWSHttpService.onRefresh call. This function accepts the response of the refresh API call and should return an object which determines the new cognito credentials.

It can happen that the request which is made to refresh the tokens fails. In order to handle this error, an extra method AWSHttpService.onRefreshError can be used. This function will return the error of the request.

import { Component, OnInit } from '@angular/core';
import { HttpRequest } from '@angular/common/http';
import { Router } from '@angular/router';
import { AWSHttpService, AWSHttpClient } from 'ngx-api-gateway-client';

@Component({
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

	constructor(
		private http: AWSHttpClient,
		private awsHttpService: AWSHttpService,
		private router: Router
	) { }

	onSubmit() {
		// Authentication request
	}

	ngOnInit() {
		// Provide a function that returns the HTTP request that should be made in order to refresh the token
		this.awsHttpService.refresh(() => {
			// Retrieve the response from our authentication request
			let data: any = window.localStorage.getItem('data');

			if (data) {
				data = JSON.parse(data);

				// Return the request that should be made in order to refresh the token
				return new HttpRequest('POST', '/refreshtoken', {
					token: data.RefreshToken,
					identity: data.IdentityId
				});
			}

			return undefined;
		});

		// Provide a function that receives the `/refreshtoken` HTTP response and returns the new token and identity id
		this.awsHttpService.onRefresh((result: any) => {
			// Update the login result
			window.localStorage.setItem('data', JSON.stringify(data));

			// Return an object with the new `Token` and `IdentityId`
			return {
				Token: result.Token,
				IdentityId: result.IdentityId
			};
		});

		// This method will be executed when the refresh request fails.
		this.awsHttpService.onRefreshError((error: any) => {
			// Refresh request has failed

			// Inform the user
			// ex. redirect user to the login page
			this.router.navigate([`/login`]);
		});
	}
}

License

MIT © Sam Verschueren