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

shuttle-can-api

v1.1.2

Published

Simple web-api client for use with CanJS.

Downloads

35

Readme

shuttle-can-api

Provides a mechanism to interact with your web/rest api.

Installation

npm install shuttle-can-api

Options

url

You can set a default base url for all your calls; this url can be overridden in individual call by using a full url that start with http|https.

import {options} from 'shuttle-can-api';

Once you have retrieved the options you set the values:

options.url = 'http://endpoint';

Instantiation

You need to access the Api and create an instance for the relevant endpoint that you will be using. Since this is a DefineMap you instance using an object to set the attributes:

var api = new Api({endpoint: 'users'});

The above would append users to the options.url in order to obtain the full url to interact with.

var api = new Api({endpoint: 'http://another-location/users'});

The above already has the full url to interact with so the options.url would not be used.

Other options that you can set are:

Options

var api = new Api({
        endpoint: 'http://another-location/users',
        cache: true|false,
        Map: DefineMap,
        List: DefineList
    });

cache

By default caching is disabled for all calls.

Map

If you'd like responses to coerce individual objects to a specific DefineMap you can set it in the Map attribute.

List

To change an entire list into a specific DefineList you can specify it using the List attribute.

Usage

parseEndpoint(endpoint, parameters)

Although this method would typically not be called directly it is used in other calls to get the full url to use in the ajax call.

The parameters is an object that contains the parameter values that should be named as they are in the endpoint.

For instance, an endpoint such as users/{action}/{id} would require a parameter object such as this:

{
    id: 1,
    action: 'disable'
}

This would result in the endpoint parsed to users/disable/1.

list(parameters)

Returns a promise that will resolve to a DefineList or the specified List attribute:

api.list()
    .then(function (list) {
        list.ForEach(function(item) {
           // do something 
        });
    })

map(parameters)

Returns a promise that will resolve to a DefineMap or the specified Map option:

api.map({id: 2})
    .then(function (item) {
        // do something
    })

If the data returned from the endpoint is not an object then a ValueMap is returned that simply has a value property.

post(data, parameters)

Send data to the endpoint.

api.post({ message: 'success' })
    .then(function (response) {
        // do something
    });

put(data, parameters)

Replaces data on the endpoint.

api.put({ message: 'success' }, { id: 2 })
    .then(function (response) {
        // do something
    });

delete(parameters)

Removes the request resource.

api.delete({id: 2})
    .then(function (response) {
        // do something
    });