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

es6-resource-client

v0.1.0

Published

A simple HTTP client wrapper with methods built to mirror Laravel's resource controller methods.

Downloads

4

Readme

Resource Client

An ES6 HTTP client wrapper with methods built to mirror Laravel's resource controller methods.

I find that in many of my Laravel apps I am only making Ajax calls to API routes which eventually resolve to controller methods with one of the following five names (from Laravel's resource controller docs).

  • index : Fetch an array of all existing records
  • store : Store a new record in the database
  • show : Fetch a single record
  • update : Make changes to a single existing record
  • destroy: Remove a single existing record

To lighen the cognitive load of switching between Laravel and Javascript I decided to extend the names of these server-side controller methods into a client-side Resource client designed format resource requests in a way that will make Laravel happy.

Installation & Usage

First run:

npm install --save danielcoulbourne/resource-client

Then:

  1. Import the client at the top of your file
  2. Store your API Bearer token in the global App.api_key (I'll be making this configurable soon)
  3. Use one of the supported methods (outlined in the next section) to make some calls.
  4. Each method returns a Promise which resolves with the server data, so you'll want to catch it in a then()

Example:

import Resource from 'resource-client';

Resource.index('users').then(users => {
	console.log(users);
});

Parameters

All methods take a string as their first parameter – the name of the resource as it appears in the route.

Index – index(resource)

Index does not take any additional parameters. Ex. -

Resource.index('users')

Store – store(resource, record)

Store takes a second parameter, an object with the record to be stored. Ex. -

Resource.store('users', { email: '[email protected]' })

Show – show(resource, recordId)

Show takes a second parameter, the ID of the associated record. Ex. -

Resource.show('users', 1)

Update – update(resource, record)

Update takes a second parameter, an object with the record to be updated. This object must, at a minimum, include the ID of the record in the database. Ex. -

Resource.update('users', { id: 1, email: '[email protected]' })

Destroy - destroy(resource, id)

Destroy takes a second parameter, the id of the record to be destroyed.

Tighten Love

This package is the result of the awesome culture and conversation that happens at TightenCo. Special thanks to the homies Caleb Porzio and Samantha Geitz.

This is far from over.