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

endpointsjs

v0.3.5

Published

Simple library for HTTP service clients

Downloads

15

Readme

Endpoints

Build Status

Simple helper library for HTTP service clients. Endpoints works in the browser and in Node, using RequestAdapter to expose a common interface for Request Response objects, and superagent for Node and browser AJAX.

View the Endpoints API Reference.

tl;dr

var Endpoints = require('endpointsjs');

var myEndpoint = Endpoints.create('/some/url/pattern')
  .header('Content-Type', 'application/json')
  .methods(['get', 'post']);

myEndpoint.get()
  .send()          // Returns an Q Promise (Promises/A+)
  .invoke('text')  // You may invoke any method a RequestAdapter implements
  .done(console.log);

Install it

npm install endpointsjs

Usage

Use Endpoints to create an endpoint pattern, then call methods on that pattern and get promises back. No pyramid of doom. Code over configuration.

var Endpoints = require('endpointsjs');

var myEndpoint = Endpoints
  .create('/some/url/pattern')
  .header('Content-Type', 'application/json')
  .methods(['get', 'post']);

var promise = myEndpoint
  .get()
  .send(); // Returns an Q Promise (Promises/A+)

// You can do something like this
promise
.then(function(requestAdapter) {
  return requestAdapter.text();
})
.done(function(text) {
  console.log(text);
});

// Which is equivalent to
promise
.invoke('text')
.done(console.log);

Sending data to the server is also easy

var myOtherEndpoint = Endpoints.create('/some/other/url/pattern')
  .methods(['options', 'post', 'delete']);

myOtherEndpoint.post()
  .data({myData: 123})
  .send()
  ...
  .done();

It is also possible to build a URL by passing arguments

var myOtherEndpoint = Endpoints
  .create('/users/[userId]-[username]')
  .methods('get');

myOtherEndpoint
  .post()
  .param('userId', 123)
  .param('username', 'kahnjw')
  .send() // GETs the URL: /users/123-kahnjw
  ...
  .done();

Development

Bug fixes, new features, doc fixes are welcome and ecouraged. Open your pull early, make sure the code lints without error and the tests pass.

Setup

$ git clone [email protected]:kahnjw/endpoints.git
$ cd endpoints
$ npm install

Lint and test

$ gulp lint
$ gulp browserspec
$ gulp nodespec

Or just use the watch task

$ gulp watch

If new features are added or a bug is fixed, please cover them with new tests.

Footprint

Keep in mind this library is targeting both browser and Node environments. Footprint size should be as small as possible. To help with this there is a footprint task:

$ gulp footprint
[gulp] Using gulpfile ~/Documents/endpoints/gulpfile.js
[gulp] Starting 'footprint'...
[gulp] gulp-size: total 57.35 kB
index.js
└─┬ create.js
  ├─┬ http-method-helper.js
  │ └─┬ http-method.js
  │   ├── ../node_modules/lodash/dist/lodash.js
  │   ├─┬ ../node_modules/qagent/index.js
  │   │ └── ../node_modules/q/q.js
  │   └─┬ ../node_modules/superagent/lib/client.js
  │     ├── ../node_modules/superagent/node_modules/component-emitter/index.js
  │     └── ../node_modules/superagent/node_modules/reduce-component/index.js
  ├─┬ ../node_modules/requestadapter/src/index.js
  │ ├── ../node_modules/requestadapter/src/xhr-adapter.js
  │ └── ../node_modules/requestadapter/src/node-request-adapter.js
  └── ../node_modules/lodash/dist/lodash.js

[gulp] Finished 'footprint' after 1.4 s

This prints out the minified size of the library, and the dependency tree to ensure that no libraries are double included.