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

api-consumption-layer

v1.2.0

Published

Package created to implement an abstract of consumption layer for RestAPI in Angular projects for equals or later versions to 7.

Downloads

18

Readme

API Consumption Layer

Package created to implement an abstract of consumption layer for RestAPI in Angular projects for equals or later versions to 7.

Stats

Build Status Build Status

Why?

We know that angular is component oriented but over time and with project growth, if there is no basic design organization, it will get confusing and difficult to maintain. So in order to improve maintenance and start a project in a structured way, I created this package.

Install

Run the command: npm i api-consumption-layer --save

After install packege, you need to create a model and service, for example:

Model [product.model.ts]

 export  class  Product {
	    id: number;
	    name: string;
	    description: string;
	    providerId: number;
	    subCategoriaId: number;
	    unity: string;
	    initialInventory: string;
	    previousBalance: string;
	    currentBalance: string;
	    cost: string;
	    price: string;
	    status: number;
}

Environment [src/environments/environment.ts and environment.prod.ts]

export const environment = {
  urlApi: 'http://localhost:3330/api', //include your url api
};

Service [product.service.ts]

import { Injectable } from '@angular/core';
import { CoreApiService } from 'api-consumption-layer';
import { Product  as Entity } from  '../models/product.model';
import { environment } from '../../../environments/environment';

/* Path da API */
const resourceName:  string  =  'products';

@Injectable({
    providedIn:  'root'
})
export  class  ProductService {
    constructor(public  restApi:  CoreApiService<Entity>) {
    	    this.restApi.setUrl(environment.urlApi);
	    this.restApi.setResource(resourceName);
    }
}

You can use this service like this:

Component [CartComponent.ts]

import { Component, OnInit } from  '@angular/core';
import { ProductService } from  'src/app/services/product.service';
import { Product } from  'src/app/models/product.model';

@Component({
    selector:  'app-cart',
    templateUrl:  './cart.component.html',
    styleUrls: ['./cart.component.scss']
})

export  class  CartComponent  implements  OnInit {
    dataSource: Product[];
    isLoadingResults: boolean;

    constructor(private productService: ProductService) { }

    ngOnInit() {
	    this.productService.restApi.get().subscribe(res  => {
		    this.dataSource = res;
		    console.log(this.dataSource);
		    this.isLoadingResults =  false;
	    }, err  => {
		    console.log(err);
		    this.isLoadingResults =  false;
	    });
    }
}

if you have problems with XSS (cross-site-script) because you are on different domains, do this:

  • Create the file proxy.config.js and applied the content:

    const proxy = [{
      context: '/api',
      target: 'http://localhost:3330',
      pathRewrite: {'^/api' : ''}
    }];
    module.exports = proxy;
  • After to do it, your api will be availibity in the same domain your application with suffix api, for example: your web application is running in port 4200, your api will be running in the same port with suffix api (localhost:4200/api).

  • You can use the command ng serve --open --proxy-config proxy.config.js for execute it.

Credits

I ask you to contribute to our improvement. It was my first npm package.

Contact

[email protected]