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

lgx-axios-dev-tools

v1.0.3

Published

Libreria de Javascript/Typescript basada en axios para hacer consultas en api. Permite recuperar, actualizar y eliminar objectos a través de una sintaxis clara y facil de utilizar. Las consultas se pueden hacer con observables o promesas.

Downloads

2

Readme

lgx-axios-dev-tools

Libreria de Javascript/Typescript basada en axios para hacer consultas en api. Permite recuperar, actualizar y eliminar objectos a través de una sintaxis clara y facil de utilizar. Las consultas se pueden hacer con observables o promesas.

Instalación

npm install lgx-axios-dev-tools --save

Uso

Crear una clase base que extienda de Model de lgx-axios-dev-tools con la url base.

import { Model } from "lgx-axios-dev-tools";

export class Base extends Model {
  baseUrl() {
    return "http://localhost:3000";
  }
}

Crear modelos a partir de la clase base.

export class User extends Base {
  resource = "users";
}

Métodos

Promesas

find

// find(page?: number, perPage?: number): Promise<any>;
const resp = await User.find();

findById

// findById(id: string | number): Promise<any>;
const resp = await User.findById(120);

save

// save(model: ILgxModel): Promise<any>;
const resp = await User.save({
  firstName: "Luis gabriel",
  lastName: "Acevedo ramírez"
});

update

// update(id: string | number, model: ILgxModel): Promise<any>;
const resp = await User.update(1, {
  id: 1,
  firstName: "Luis gabriel",
  lastName: "Acevedo ramírez"
});

destroy

// destroy(id: string | number): Promise<any>;
const resp = await User.destroy(1);

Observables

findRx

// findRx(page: number, perPage: number): Observable<any>;
User.findRx().subscribe(resp => console.log(resp));

findByIdRx

// findByIdRx(id: string | number): Observable<any>;
User.findById(120).subscribe(resp => console.log(resp));

saveRx

// saveRx(model: ILgxModel): Observable<any>;
User.saveRx({
  firstName: "Luis gabriel",
  lastName: "Acevedo ramírez"
}).subscribe(resp => console.log(resp));

updateRx

// updateRx(id: string | number, model: ILgxModel): Observable<any>;
User.updateRx(1, {
  id: 1,
  firstName: "Luis gabriel",
  lastName: "Acevedo ramírez"
}).subscribe(resp => console.log(resp));

destroyRx

// destroyRx(id: string | number): Observable<any>;
User.destroyRx(1).subscribe(resp => console.log(resp));

Query

page

// page(page: number): Builder;
const resp = await User.page(1).find();

perPage

// perPage(page: number): Builder;
const resp = await User.page(1)
  .perPage(10)
  .find();

noPagination

// noPagination(): Builder
const resp = await User.noPagination().find();

orderBy

// orderBy(attribute: string, direction?: ELgxSortDirection): Builder;
import ELgxSortDirection from "lgx-axios-dev-tools";
const resp = await User.page(1)
  .perPage(10),
  .orderBy("updateAt", ELgxSortDirection.ASC)
  .find();

with

// with(value: string | string[]): Builder;
const resp = await User.page(1)
  .perPage(10),
  .orderBy("updateAt", ELgxSortDirection.ASC)
  .with("settings")
  .find();

option

// option(queryParameter: string, value: string): Builder;
const resp = await User.page(1)
  .perPage(10),
  .orderBy("updateAt", ELgxSortDirection.ASC)
  .with("settings"),
  .option("active", "true")
  .find();

filter

// filter(attribute: string, value: string): Builder;
const resp = await User.page(1)
  .perPage(10),
  .filter("status","ACTIVE")
  .find();

where

// where(attribute: string, value: string): Builder;
const resp = await User.page(1)
  .perPage(10),
  .where("company","2")
  .find();

FormData

// formData(): Builder;
const resp = await User.formData().save({
  firstName: "Luis gabriel",
  lastName: "Acevedo ramírez",
  image: {} // Objeto de tipo File o Blob
});

Métodos Url

url

// url(url: string): Builder;
const resp = await User.url("/newUrlParams").find();

urlParam

// urlParam(urlParam: string): Builder;
const resp = await User.urlParam("urlParams").find();

Header

// header(header: string, value: string): Builder;
const resp = await User.header("pin_code", "123456").destroy(23);

Interceptor

import { Model } from "lgx-axios-dev-tools";

export class YoutubeBaseModel extends Model {
  public baseUrl() {
    return "https://www.googleapis.com/youtube";
  }
}

YoutubeBaseModel.getInstance().interceptors.request.use(request => {
  request.headers["Authorization"] ="Token"
  console.log(request);
  return request;
});

YoutubeBaseModel.getInstance().interceptors.response.use(response => {
  console.log(response);
  return response;
});

Como cambiar los valores de salida de los parámetros de la query

import { Model, ILgxQueryConfig } from "lgx-axios-dev-tools";

export class Base extends Model {
  public queryConfig: ILgxQueryConfig = {
    orderBy: "sort",
    with: "embed",
    per_page: "itemsPerPage"
  };

  baseUrl() {
    return "http://localhost:3000";
  }
}

React

import React, { Component } from "react";
import { Model, ELgxSortDirection, ILgxResponse } from "lgx-axios-dev-tools";

class BaseModel extends Model {
  public baseUrl() {
    return "http://localhost:3000";
  }
}

class Product extends BaseModel {
  public resource = "products";
}

class App extends Component {
  public page = 1;
  public perPage = 10;
  state = {
    products: []
  };

  componentDidMount() {
    this.loadProducts();
  }

  public async loadProducts() {
    const resp: ILgxResponse = await Product.page(this.page)
      .perPage(this.perPage)
      .orderBy("updateAt", ELgxSortDirection.DESC)
      .find();

    // http://localhost:3000/products?orderBy=-updatedAt&page=1&per_page=10

    this.setState({
      products: resp.data
    });
  }

  render() {
    return <div className="App">{/* Table */}</div>;
  }
}

export default App;

React native

import React, { Component } from "react";
import { Text, View } from "react-native";
import { Model, ELgxSortDirection, ILgxResponse } from "lgx-axios-dev-tools";

class BaseModel extends Model {
  public baseUrl() {
    return "http://localhost:3000";
  }
}

class Product extends BaseModel {
  public resource = "products";
}

class App extends Component {
  public page = 1;
  public perPage = 10;
  state = {
    products: []
  };

  componentDidMount() {
    this.loadProducts();
  }

  public async loadProducts() {
    const resp: ILgxResponse = await Product.page(this.page)
      .perPage(this.perPage)
      .orderBy("updateAt", ELgxSortDirection.DESC)
      .find();

    // http://localhost:3000/products?orderBy=-updatedAt&page=1&per_page=10

    this.setState({
      products: resp.data
    });
  }

  render() {
    return (
      <View>
        <Text>{/* Table */}</Text>
      </View>
    );
  }
}

export default App;

Angular

import { Component, OnInit } from "@angular/core";
import { Model, ELgxSortDirection } from "lgx-axios-dev-tools";

class BaseModel extends Model {
  public baseUrl() {
    return "http://localhost:3000";
  }
}

class Product extends BaseModel {
  public resource = "products";
}

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
  public page = 1;
  public perPage = 10;
  public products: object[] = [];
  constructor() {}

  ngOnInit() {
    this.loadProducts();
  }

  loadProducts() {
    Product.page(this.page)
      .perPage(this.perPage)
      .orderBy("updatedAt", ELgxSortDirection.DESC)
      .findRx()
      .subscribe(products => (this.products = products));

    // http://localhost:3000/products?orderBy=-updatedAt&page=1&per_page=10
  }
}

Vue

import { Component, Vue } from "vue-property-decorator";
import Template from "./App.vue";
import { Model, ELgxSortDirection, ILgxResponse } from "lgx-axios-dev-tools";

class BaseModel extends Model {
  public baseUrl() {
    return "http://localhost:3000";
  }
}

class Product extends BaseModel {
  public resource = "products";
}

@Component({
  mixins: [Template]
})
export default class App extends Vue {
  public page = 1;
  public perPage = 10;
  public products: object[] = [];

  public mounted() {
    this.loadProducts();
  }

  public async loadProducts() {
    const resp: ILgxResponse = await Product.page(this.page)
      .perPage(this.perPage)
      .orderBy("updateAt", ELgxSortDirection.DESC)
      .find();

    // http://localhost:3000/products?orderBy=-updatedAt&page=1&per_page=10

    this.products = resp.data;
  }
}