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

yslow-data-rest-api

v0.1.4

Published

REST API for storing YSlow performance data

Downloads

3

Readme

yslow-data-rest-api

Code Climate

A REST API for storing web performance data from YSlow.

It receives test results using YSlow's beacon mechanism and makes them available through a JSON API. Data is persisted to MongoDB with the yslow-data-service package.

Requirements

Installation

npm install yslow-data-rest-api

Usage

Start the server:

yslow-data-rest-api

Configure YSlow to send requests to the beacon end-point. Here's an example with YSlow for PhantomJS:

phantomjs yslow.js -b http://localhost:3000/beacon -i basic http://www.bbc.co.uk/

Head to http://localhost:3000/results to see the test results:

{
  "results": [
    {
      "id": "52b887a7e486520836000003",
      "timestamp": "2013-12-23T18:57:43.216Z",
      "data": {
        "v": "3.1.8",
        "w": 510283,
        "o": 76,
        "u": "http://www.bbc.co.uk/",
        "r": 87,
        "i": "ydefault",
        "lt": 1706
      }
    }
  ]
}

Configuration

To start the server on a different port/host then use the -p and -H flags:

yslow-data-rest-api -p 8080 -H localhost

By default the REST API is configured to use a MongoDB database at mongodb://127.0.0.1:27017/yslow. To change this, set the environment variable YSLOW_DATA_DB e.g.

EXPORT YSLOW_DATA_DB="mongodb://127.0.0.1:27017/some_db"

API

POST /beacon

Accepts YSlow beacon requests

Example request

curl -i -X POST -H "Content-Type: application/json" -d '{"v": "3.1.8", "w": 510283, "o": 76, "u": "http://www.bbc.co.uk/", "r": 87, "i": "ydefault", "lt": 1706}' http://localhost:3000/beacon

Example response

HTTP/1.1 201 Created
Location: /results/52b88a9ca7b09dcc36000001
{
  "results": [
    {
      "id": "52b8c2bc1544b91d5a000001",
      "timestamp": "2013-12-23T23:09:48.626Z",
      "data": {
        "v": "3.1.8",
        "w": 510283,
        "o": 76,
        "u": "http://www.bbc.co.uk/",
        "r": 87,
        "i": "ydefault",
        "lt": 1706
      }
    }
  ]
}

GET /results

Returns stored results

Parameters

  • url - Filters results by URL
  • limit - Limits the number of results returned

Example request

curl -i "http://localhost:3000/results?url=http://www.bbc.co.uk/&limit=5"

Example response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
  "results": [
    {
      "id": "52b8c26e6a9782d25900001a",
      "timestamp": "2013-12-23T23:08:30.229Z",
      "data": {
        "v": "3.1.8",
        "w": 538060,
        "o": 76,
        "u": "http://www.bbc.co.uk",
        "r": 88,
        "i": "ydefault",
        "lt": 1883
      }
    }
  ]
}

DELETE /results

Deletes all results

Example request

curl -i -X DELETE http://localhost:3000/results

Example response

HTTP/1.1 204 No Content

GET /results/:id

Returns a single result by its ID

Example request

curl -i http://localhost:3000/results/52b88c58a3d2f8fd36000004

Example response

{
  "results": [
    {
      "id": "52b8c26e6a9782d25900001a",
      "timestamp": "2013-12-23T23:08:30.229Z",
      "data": {
        "v": "3.1.8",
        "w": 538060,
        "o": 76,
        "u": "http://www.bbc.co.uk",
        "r": 88,
        "i": "ydefault",
        "lt": 1883
      }
    }
  ]
}

DELETE /results/:id

Deletes a single result by its ID

Example request

curl -i -X DELETE http://localhost:3000/results/52b88c58a3d2f8fd36000004

Example response

HTTP/1.1 204 No Content

GET /results/latest

Returns the latest result

Parameters

  • url - Returns the latest result for the given URL

Example request

curl -i "http://localhost:3000/results/latest?url=http://www.bbc.co.uk"

Example response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
  "results": [
    {
      "id": "52b8c4c2c4dea4fb5c00001b",
      "timestamp": "2013-12-23T23:18:26.710Z",
      "data": {
        "v": "3.1.8",
        "w": 538060,
        "o": 76,
        "u": "http://www.bbc.co.uk",
        "r": 88,
        "i": "ydefault",
        "lt": 1883
      }
    }
  ]
}

GET /urls

Returns the distinct URLs that have been tested

Example request

curl -i "http://localhost:3000/urls"

Example response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
  "urls": [
    "http://www.bbc.co.uk/weather/",
    "http://www.bbc.co.uk/news/"
  ]
}