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

pilou

v0.1.4

Published

http crud library for making web requests with promises

Downloads

13

Readme

Build Status

Pilou

http crud library for making web requests with promises

Requirements

  • ES6
  • node 4+

Install

npm install pilou

Create resource

    import resource from 'pilou';
    
    pilou(resourceName, [options])

exemple create clients resource

    import resource from 'pilou';
    
    const clients = resource('clients')

Default actions

pilou.all([config])
pilou.delete([config])
pilou.get(data[, config])
pilou.create(data[, config])
pilou.update(data[, config])

API

All

  import resource from 'pilou';
  
  const clients = resource('clients');
  
  // GET /api/clients/
  clients.all().then(response => {
    console.log(response.data);
    console.log(response.status);
  });

Get

  // GET /api/clients/c8e4f983-8ffe-b705-4064-d3b7aa4a4782/
  clients.get({id: 'c8e4f983-8ffe-b705-4064-d3b7aa4a4782'});

Create

  // POST /api/clients/ {name: 'client name'}
  clients.create({name: 'client name'});

Update

  // PUT /api/clients/c8e4f983-4064-8ffe-b705-d3b7aa4a4782/
  clients.update({id: 'c8e4f983-4064-8ffe-b705-d3b7aa4a4782'}, {name: 'updated name'});

Delete

  // DELETE /api/clients/c8e4f983-4064-8ffe-b705-d3b7aa4a4782/
  clients.delete({id: 'c8e4f983-8ffe-4064-b705-d3b7aa4a4782'});

Headers and Params

  const config = {
    headers: {Authorization: `JWT ...`},
    params: {date: '-created'}
  };
  // GET /api/clients/?date=-created
  clients.all(config);

Options

customize endpoints

    const equipments = resource('equipments', {
      all: '/api/v2/${resource}',
      get: '/api/v2/${resource}/${equipmentId}'
    });
    
    // GET /api/v2/equipments
    equipments.all();
    
    // POST /api/v2/equipments {equipmentName: 'foo'}
    equipments.create({equipmentName: 'foo'});
    
    // GET /api/v2/equipments/42
    equipments.get({equipmentId: 42});
    
    // PUT /api/v2/equipments/42 {equipmentName: 'foo'}
    equipments.update({equipmentId: 42}, {equipmentName: 'foo'});

customize every endpoints

    const equipments = resource('equipments', {
      all: '/api/all/${resource}/',
      create: '/api/v2/${resource}',
      get: '/api/get/${resource}/${id}/',
      update: '/api/update/${resource}/${id}/',
      delete: '/api/v2/${resource}/${id}'
    });

Request Config

These are the available config options for making requests.

{
  // `url` is the server URL that will be used for the request
  url: '/user',

  // `baseURL` will be prepended to `url` unless `url` is absolute.
  // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
  // to methods of that instance.
  baseURL: 'https://some-domain.com/',

  // `headers` are custom headers to be sent
  headers: {'X-Requested-With': 'XMLHttpRequest'},

  // `timeout` specifies the number of milliseconds before the request times out.
  // If the request takes longer than `timeout`, the request will be aborted.
  timeout: 1000,

  // `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
  // This will set an `Authorization` header, overwriting any existing
  // `Authorization` custom headers you have set using `headers`.
  auth: {
    username: 'admin',
    password: 'password'
  }

  // `responseType` indicates the type of data that the server will respond with
  // options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
  responseType: 'json', // default

  // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
  xsrfCookieName: 'XSRF-TOKEN', // default

  // `xsrfHeaderName` is the name of the http header that carries the xsrf token value
  xsrfHeaderName: 'X-XSRF-TOKEN', // default

  // `maxContentLength` defines the max size of the http response content allowed
  maxContentLength: 2000
}

License

MIT - see license file