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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tnt.rest

v0.1.1

Published

Library to retrieve data via RESTful APIs

Downloads

17

Readme

TnT Rest

tnt.rest is a library to retrieve data from RESTful APIs.

Installation

Installation can be made with npm:

npm install --save tnt.rest

or from Git:

git clone https://github.com/tntvis/tnt.rest
cd tnt.rest
npm install
npm build-browser

Usage

Example of usage:

<head>
    <script src="build/tnt.rest.js"></script>
</head>

<body>
    <div id="mydiv"></div>
    <script>
    var rest = tnt.rest()
        .domain("rest.ensembl.org")

    var url = rest.url()
        .endpoint("xrefs/symbol/:species/:id")
        .parameters({
            "species": "human",
            "id": "BRCA1",
        });

    rest.call(url)
        .then (function (resp) {
            var data = resp.body;
            // use data
        });
    </script>
</body>

See the examples folder for more examples.

API

tnt.rest() returns a new rest instance that exposes the following methods:

prefix

Specifies any prefix to be added to the URI. This is useful for calls that are proxy-ed through a web server that expects a given prefix in the URIs. This prefix is inserted even before the protocol

var rest = tnt.rest()
    .prefix ("/proxy/");
protocol

Specifies the protocol to be used (http by default).

domain

Specifies the domain for the URI.

var rest = tnt.rest()
    .domain("rest.ensembl.org");
port

Specifies the port to use for the URI.

var rest = tnt.rest()
    .port(9988);

call

Performs a call using the provided url. By default a GET request is made. The first argument is mandatory and can be a string specifying the complete URI for the resource or a tnt.rest.url instance (see below). If the former any prefix, protocol, domain and port set via the API are ignored. If the latter those options are used to build the resource URI. If a second argument is provided and is an object a POST request is made using this object as its post data. The method returns an ES6-compliant promise that can be chained via its then method and errors are catchable via its catch method.

Example of GET request:

var rest = tnt.rest();
rest.call("http://rest.ensembl.org/xrefs/symbol/homo_sapiens/BRCA2?content-type=text/xml")
    .then (function (resp) {
        // do something with resp
    })
    .catch(function (err) {
        // do something with err
    })

Example of POST request:

var rest = tnt.rest();
rest.call("http://rest.ensembl.org/lookup/id?content-type=application/json", {
    "ids" : ["ENSG00000157764", "ENSG00000248378" ]
})
    .then (function (resp) {
        // do something with resp
    })

tnt.rest.url

tnt.rest.url provides an interface to build URIs using its API. Using this API is not mandatory since you can pass directly the URI string to the call method (see above for examples). The returned url instance exposes several methods explained below.

var rest = tnt.rest()
    .endpoint("rest.ensembl.org");
var url = rest.url()
    .endpoint("xrefs/symbol/:species/:id")
    .parameters({
        "species": "human",
        "id": "BRCA1"
    });
rest.call(url)
    .then (function (resp) {
        // do something with resp
    });
endpoint

Specifies the path field in the URI. If the endpoint string contains arguments (ie, parts starting with a ":") they are substituted by their corresponding options in the parameters method.

var rest = tnt.rest();
var url = rest.url()
    .endpoint("xrefs/symbol/:species/:id")
    .parameters({
        "species" : "human",
        "id"      : "BRCA1"
    });
parameters

Sets the endpoint arguments and optional parameters in the URI. It accepts an object whose properties are the name of the argument / parameter and the values their value. Array values are allowed making the parameter to be repeated as many times as items are in the array.

var rest = tnt.rest();
var url = rest.url()
    .endpoint("xrefs/symbol/:species/:id")
    .parameters({
        "species" : "human",
        "id"      : "BRCA1",
        "feature" : ["gene", "cds"]
    });
fragment

Sets an optional fragment for the URI (ie, the anchor after the "#" in a URI).

Feedback

Please, send any comments to [email protected]. Bug reports and feature requests are welcome in the issue tracker