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

jampper

v1.0.2

Published

Javascript API Mapper

Downloads

4

Readme

Jampper

Jampper is a simple and straightforward library for mapping RESTful APIs. As it internally uses jQuery's ajax module for performing the requests, almost evertything you can do with jQuery.ajax you can do with Jampper.

Installing

NPM

$ npm install jampper

Bower

$ bower install jampper

Building from source

Clone the repository and run :

$ npm install
$ node build.js

Embedding

Regardless of the way you have chosen to install the lib, de dist directory will contain the compiled files.

If you have already loaded the jQuery in your page, you should use the jampper.jquery.js file:

<script src="path/to/jquery.js"></script>
<script src="path/to/jampper/dist/jampper.jquery.js"></script>

Otherwise, the jampper.js file should be used :

<script src="path/to/jampper/dist/jampper.js"></script>

Usage

To create a Jampper object of a REST API, you will need to provide the API host and the resources object :

var api = new Jampper('https://api.github.com/', {
  users : null,
  search : {
    repositories : null
  },
  repos : {
    commits : {
      sha : null
    },
    contributors : null
  }
});

Note: You can also map resources with file extensions (i.e. users.json). jampper will strip the extension and expose the resource method as users.

In order to perform a GET to the users/rafaeldias :

api.users('rafaeldias').read(function(res) {
  ...
});

The snippet above is equivalent to :

GET https://api.github.com/users/rafaeldias

CRUD operations

In addition to the read method, there are three more methods that by default all resources will inherit in order to perform CRUD operations, each of these methods are mapped to an HTTP verb :

  • create([options[, callback]]) - POST /resource
  • update([options[, callback]]) - PUT /resource
  • delete([options[, callback]]) - DELETE /resource

You can add or overwrite methods mapped to HTTP verbs by calling the mapMethod method of the Jampper object:

Jampper.mapMethod({
  'update' : 'PATCH',
  'edit'   : 'PUT'
});

Now the next time we call the overwritten update method on a resouce, the HTTP verb PATCH will be used in the request, and the new edit method will send the PUT HTTP verb to the server.

Request options

Every CRUD method may receive an object of options as its first parameter. These options are the same as stated in the jQuery ajax documentation.

Callbacks

The arguments of the callback passed to any of the CRUD methods may be different depending on the status of the request.

  • In case of successful request, the arguments are:

    • data: The response from the server
    • textStatus: A string categorizing the status of the request (success, notmodified, error, ...)
    • jqXHR: A superset of the browser's native XMLHttpRequest object. For more information see jQuery's jqXHR section
  • In case of failed requests, the arguments are:

    • jqXHR: As described above.
    • textStatus: As described above.
    • errorThrown: An exception object. When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error".

The done, fail and always methods are also exposed by jampper.

Global Setup

Jampper also exposes the .setup method, so it's possible to configure global ajax properties even if user is not using jQuery.

License

Jampper is released under the MIT license.