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

jquery-ajax-request

v0.0.6

Published

Module that allows you to perform ajax requests in the browser. A wrapper around $.ajax, inspired by superagent.

Downloads

12

Readme

Overview

Just a wrapper around Jquery to perform ajax requests in a browser more easily. Basically copy of superagent nice api.

Has a built in support for cache of requests, you just have to inform your retrieve/store functions in your cache system.

Bundled with browserify

Required Dependencies

  • jquery
  • lodash (or underscore)

Included Dependencies

  • URIjs
  • json-stable-stringify

Browser

  • can be acessed as global window.ajaxRequest

Browserify

  • Uses browserify-shim as transform.

Options

  • defaultFailHandler optional
    • receives same arguments as jquery fail function, should be a function that is going to be called when errors happen. It can be overriden in a single request by calling .fail(fn)
  • onBeforeRequestStarts optional
    • called before a request is started, it can be used to set up UI
    • receives own request as a parameter, so you can access information
  • onRequestEnded optional
    • called when a request ends
    • receives own request as a parameter
  • injectData optional
    • function used to inject data into JSON being sent
    • useful to inject security tokens
    • receives the json as parameter, should return a json
    • if you use cache option, this wont be used as a cache key

Options when using request.option('useCache', true)

  • retrieveCache(key, callback) optional
    • callback must return data from cache, or falsy value if there is nothing there
  • storeCache(key, value) optional
    • should store value as key in your cache
  • appendToCacheKey
    • String to append to cache key.
    • eg: lets say your user changes website language. Then your cache data could be invalid if data cached depends on the language. Considering language is not specified in your actual request (with a query param), that would solve the issue as well.

API

  • Request(method, url) constructor
    • creates a new instance of Request
  • Request.post(url)
    • creates a new instance of Request
  • Request.get(url)
    • creates a new instance of Request
  • Request.put(url)
    • creates a new instance of Request
    • notice, not all browsers support this, you should probably use POST, and some technique to override methods in your server
  • Request.delete(url)
    • creates a new instance of Request
    • notice, not all browsers support this, you should probably use POST, and some technique to override methods in your server
  • Request.del(url) alias of Request.delete
  • query(json)
    • copies all data from json into current Request query object
  • send(json)
    • sets post data into request
    • it can be a knockout observable object, it will be converted back to JSON
  • option(option, value)
    • sets a option and value into Request.options
    • options supported internally
      • useCache
      • acceptsJSON
  • acceptsText() uses option method
  • acceptsJSON() default internal option, uses option method
  • useCache() uses option method
  • fail(fn)
    • sets new function as fail handler
  • end(callback)
    • performs the request, calling callback with data received, in case of success. In case of failure, it will be handled by the fail handler.

Request Attributes (can be accessed in a few handlers)

  • options
  • url
  • _query internal
  • _json internal

Usage

Request = require('mmw-cli-request')({})

Request.post("/registration").send({abc:"123"}).end (data)->
  console.log data