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

safe-rest

v0.0.23

Published

### Install node and update to latest version As of May 4, 2016, the latest version is 6.0.0. ``` nvm install v6.0.0 nvm alias default v6.0.0 ```

Downloads

21

Readme

safe-rest

Install node and update to latest version

As of May 4, 2016, the latest version is 6.0.0.

nvm install v6.0.0
nvm alias default v6.0.0

Clone repo

git clone https://github.com/sdurbin1/safe-rest.git

Install safe-rest

cd /path/to/safe-rest
npm install

Ensure mongo is running

Run in separate terminal, or in background

mongod --smallfiles

Populate database with test data

npm run-script db-fill

Edit config.js

Edit the appropriate line in config.js

exports.host = 'https://safe-app-<username>.c9users.io'

Run application

node app.js

Rest API and example calls

POST /analytics

Create an analytic

curl localhost:8080/analytics/ -H "Content-Type: application/json" --data '{"name": "Normal Distribution"}'
GET /analytics

Return all analytics

curl localhost:8080/analytics
GET /analytics/:analytic

Return an analytic

curl localhost:8080/analytics/56e816d8abda61a618bfccd5
PUT /analytics/:analytic

Update an analytic

curl localhost:8080/analytics/56ea975aec9cc0f3098ae316 -H "Content-Type: application/json" -X PUT --data '{"name":"New Name"}' 
DELETE /analytics/:analytic

Delete an analytic

curl -X DELETE http://localhost:8080/analytics/56ea975aec9cc0f3098ae316
PUT /analytics/:analytic/visualization-types

Add an existing visualization-type to an analytic

curl localhost:8080/analytics/56eac298ee121e4b18d92259/visualization-types -X PUT --data 'visualizationTypes=56eaa1eae319c5af0c8dfc4d&visualizationTypes=56eaa1f1e319c5af0c8dfc4f'
GET /analytics/:analytic/visualization-types

Return a list of visualizationTypes associated with an analytic

curl localhost:8080/analytics/56e816d2abda61a618bfccd4/visualization-types
DELETE /analytics/:analytic/visualization-types/:visualization-type

Remove a visualizationType from an analytic (does not delete the visualizationType)

curl -X DELETE http://localhost:8080/analytics/56eac298ee121e4b18d92259/visualization-types/56eaa1eae319c5af0c8dfc4d
GET /visualization-types

Return all visualizationTypes

curl localhost:8080/visualization-types
POST /visualization-types

Create a visualizationType

curl http://localhost:8080/visualization-types -H "Content-Type: application/json" -X POST --data '{"name":"Area"}'
GET /visualization-types/:visualization-type

Return a visualizationType

curl localhost:8080/visualization-types/56e8178dabda61a618bfccd9
PUT /visualization-types/:visualization-type

Update a visualizationType

curl -X PUT http://localhost:8080/visualization-types/56eaa1eae319c5af0c8dfc4d/ --data 'name=Area'
DELETE /visualization-types/:visualization-type

Delete a visualizationType

curl -X DELETE http://localhost:8080/visualization-types/56eaa1eae319c5af0c8dfc4d/
POST /sources

Create a source

curl localhost:8080/sources -H "Content-Type: application/json" -X POST --data '{"name": "CSV_01222016", "fields": [{"name":"Age","dataType":"Number"},{"name":"County","dataType":"String"},{"name":"Height","dataType":"Number"},{"name":"Latitude","dataType":"Number"},{"name":"Longitude","dataType":"Number"},{"name":"Street Address","dataType":"String"},{"name":"Weight","dataType":"Number"}]}'
GET /sources

Return all sources

curl localhost:8080/sources
GET /sources/:source

Return a source

curl localhost:8080/sources/56e85075cbe2b94312e95daf
PUT /sources/:source

Update a source

curl localhost:8080/sources/56eaec7a2308db1b1c6f795f -H "Content-Type: application/json" -X PUT --data '{"fields": [{"name":"Age","dataType":"Number"},{"name":"County","dataType":"String"},{"name":"Height","dataType":"Number"},{"name":"Latitude","dataType":"Number"},{"name":"Longitude","dataType":"Number"},{"name":"Street Address","dataType":"String"},{"name":"Weight","dataType":"Number"}]}'
DELETE /sources/:source

Delete a source

curl -X DELETE http://localhost:8080/sources/56eaec7a2308db1b1c6f795f/
PUT /sources/:source/analytics
curl localhost:8080/sources/56eaec7a2308db1b1c6f795f/analytics -X PUT --data 'analytics=56eaa9fc51ed186110af1a80&analytics=56eac298ee121e4b18d92259'
GET /sources/:source/analytics

Return all analytics associated with a source

curl localhost:8080/sources/56e865818c792b4f18f64f24/analytics
DELETE /sources/:source/analytics

Remove an analytic from a source (does not delete the analytic)

curl -X DELETE http://localhost:8080/sources/56eaec7a2308db1b1c6f795f/analytics/56eaa9fc51ed186110af1a80
GET /sources/:source/fields

Return all fields associated with a source

curl localhost:8080/sources/56eaec7a2308db1b1c6f795f/fields
POST /sources/:source/data

Upload a csv document. Creates a new collection with name "sourceId", and inserts document, "document"

curl localhost:8080/sources/56eaec7a2308db1b1c6f795f/data -H "Content-Type: application/json" --data '{"document":[{"Age":21,"County":"Anne Arundel","Height":61,"Latitude":31.33,"Longitude":33.00,"Street Address":"123 Main St.","Weight":133},{"Age":33,"County":"Howard","Height":67,"Latitude":31.33,"Longitude":33.00,"Street Address":"456 Main St.","Weight":188},{"Age":29,"County":"Anne Arundel","Height":63,"Latitude":31.33,"Longitude":33.00,"Street Address":"789 Main St.","Weight":142}]}'

Optionally include a list of fields

curl localhost:8080/sources/56eaec892308db1b1c6f7960/data -H "Content-Type: application/json" --data '{"fields": [{"name":"Age","dataType":"Number"},{"name":"County","dataType":"String"},{"name":"Height","dataType":"Number"},{"name":"Latitude","dataType":"Number"},{"name":"Longitude","dataType":"Number"},{"name":"Street Address","dataType":"String"},{"name":"Weight","dataType":"Number"}],"document":[{"Age":21,"County":"Anne Arundel","Height":61,"Latitude":31.33,"Longitude":33.00,"Street Address":"123 Main St.","Weight":133},{"Age":33,"County":"Howard","Height":67,"Latitude":31.33,"Longitude":33.00,"Street Address":"456 Main St.","Weight":188},{"Age":29,"County":"Anne Arundel","Height":63,"Latitude":31.33,"Longitude":33.00,"Street Address":"789 Main St.","Weight":142}]}'
POST /sources/data

Upload a csv document and create source.

curl localhost:8080/sources/data -H "Content-Type: application/json" --data '{"source": {"name":"TEST","fields": [{"name":"Age","dataType":"Number"},{"name":"County","dataType":"String"},{"name":"Height","dataType":"Number"},{"name":"Latitude","dataType":"Number"},{"name":"Longitude","dataType":"Number"},{"name":"Street Address","dataType":"String"},{"name":"Weight","dataType":"Number"}]},"document":[{"Age":21,"County":"Anne Arundel","Height":61,"Latitude":31.33,"Longitude":33.00,"Street Address":"123 Main St.","Weight":133},{"Age":33,"County":"Howard","Height":67,"Latitude":31.33,"Longitude":33.00,"Street Address":"456 Main St.","Weight":188},{"Age":29,"County":"Anne Arundel","Height":63,"Latitude":31.33,"Longitude":33.00,"Street Address":"789 Main St.","Weight":142}]}'
DELETE /sources/:source/data

Delete csv document associated with source

curl localhost:8080/sources/5720ade7587a45660a46cdcb/data -X DELETE
GET /sources/:source/query

Queries a data source based on a set of filters. Note: "id" field in filters data is not needed.

curl localhost:8080/sources/56eaec7a2308db1b1c6f795f/query -H "Content-Type: application/json" --data '{"filters": [{"id": "1","field": "Age","operator": ">","value": 25},{"id": "2","field": "County","operator": "=","value": "Howard"}]}'
POST /visualizations

Create a new visualization

curl http://localhost:8080/visualizations -H "Content-Type: application/json" -X POST --data '{"name":"Visualization1", "source":"56eaec7a2308db1b1c6f795f", "visualizationType":"57055c4c43176c9118cffc95", "analytic":"56eac298ee121e4b18d92259", "visualizationParams":{"title": {"text": "Monthly Average Temperature"},"subtitle": {"text": "Source: WorldClimate.com"}}, "analyticParams": [{"groupBy": ["Age"]}], "filters":[{ "id": 1,"field": "Age","operator": ">","value": 35},{"id": 2,"field": "County","operator": "=","value": "Howard"}], "analyticParams":[{"groupBy":"Age"}]}'
GET /visualizations

Return all visualizations

curl http://localhost:8080/visualizations
GET /visualizations/:visualization

Return a visualization

curl localhost:8080/visualizations/570b93b007b51d710c748fb1
PUT /visualizations/:visualization

Update a visualization

curl http://localhost:8080/visualizations/570b93b007b51d710c748fb1 -H "Content-Type: application/json" -X PUT --data '{"analyticParams":[{"groupBy":"AGE"}]}'
DELETE /visualizations/:visualization

Delete a visualization

curl -X DELETE http://localhost:8080/visualizations/570b93b007b51d710c748fb1
POST /dashboards

Create a dashboard

 curl http://localhost:8080/dashboards -X POST --data 'title=Dashboard&visualizations=570b968507b51d710c748fb2&visualizations=570b9e54ddef419e0fda43a9'
GET /dashboards

Return all dashboards

curl http://localhost:8080/dashboards
GET /dashboards/:dashboard
curl http://localhost:8080/dashboards/570b9f8a877d26ac10c3b4f1
PUT /dashboards/:dashboard

Update a dashboard

curl http://localhost:8080/dashboards/570b9f8a877d26ac10c3b4f1 -X PUT --data 'title=Dashboard1'
DELETE /dashboards/:dashboard

Delete a dashboard

curl http://localhost:8080/dashboards/570b9f8a877d26ac10c3b4f1 -X DELETE
GET /dashboards/:dashboard/visualizations

Return a list of visualizations associated with a dashboard

curl localhost:8080/dashboards/570ba706a4cc946212bdaa42/visualizations
PUT /dashboards/:dashboard/visualizations

Add an existing visualization to a dashboard

curl localhost:8080/dashboards/570ba706a4cc946212bdaa42/visualizations -X PUT --data 'visualizations=570b9e54ddef419e0fda43a9'
DELETE /dashboards/:dashboard/visualizations/:visualization

Remove a visualization from a dashboard (does not delete the visualization)

curl -X DELETE localhost:8080/dashboards/570ba706a4cc946212bdaa42/visualizations/570b968507b51d710c748fb2
GET /authenticate

Authenticate user

curl localhost:8080/authentication/authenticate
GET /execute/:visualization_id

Run analytic based on parameters of the provided visualization id and return json results.

curl localhost:8080/execute/572a1c11fbdcac91218b9a1f

Accept an optional list of filters

curl localhost:8080/execute/572a1c11fbdcac91218b9a1f -H 'Content-Type: application/json' --data '{"filters": [{"field": "Gender","operator": "=","value": "M"}]}'