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

scrapi

v0.1.0

Published

Data manager with a flexible API

Downloads

47

Readme

Scrapi

Data manager with a flexible API. A popup backend (nobackend, baas) that compliments your code or stands alone.

Scrapi can be used to setup a simple CRUD backend server with a REST interface, but also includes an internal client that provides your business logic with easy access to your data.

npm install scrapi

Usage

Basic Google Auth protected CRUD backend

Allows:

Request | Description --- | --- POST /<resourceType> with JSON payload | Create Resource PUT /<resourceType>/<resourceId> with JSON payload | Overwrite Resource GET /<resourceType>/<resourceId> | Retrieve Resource

var Scrapi = require('scrapi');

var config = {
	auth: {
		providers: [
			'google'
		]
	}
};

var scrapi = new Scrapi(config);

scrapi.start(function(data) {
	// REST server started
});

Google Auth protected CRUD backend with custom endpoints and logic

var Scrapi = require('scrapi');

var config = {
	auth: {
		providers: [
			'google'
		]
	}
};

var scrapi = new Scrapi(config);

// Get the client for internal use
var scrapiClient = scrapi.getClient();

// Create a custom REST endpoint to trigger custom logic
// Will create:
// POST /users/<userId>/congratulate
scrapi.addCommand('users', 'congratulate', function(req, res) {
	// do custom logic to congratulate user
});

// Start the REST server after all custom endpoints have been added.
scrapi.start(function(data) {
	// REST server started
});

Configuration

auth - Configures how data access should be authorized. Only Google auth is supported (shown below) (default: disabled).

data - Describes data should be persisted. Currently, only supports an embedded noSQL database.

parameter | description --- | --- data.dir | The location of the data in relation to your project root (default: 'data').

static - Configure how your site's static files should be served.

parameter | description --- | --- static.dir | The location of the files in relation to your project root (default: 'public').

Here is an example config:

var config = {
	auth: {
		providers: [
			'google'
		]
	},
	data: {
		dir: 'db'
	},
	static: {
		dir: 'assets'
	}
};

Internal client

The internal client provides your app with access to your data, ensuring changes will notify all interested clients.

The internal client contains functions that resemble the GET, POST, and PUT REST methods.

function | description --- | --- get(type, filter) | Retrieve a certain type of data that matches the given filter. type is a string. filter is either a resourceId string or an object that matches the specificiations of a mongodb query post(type, data) | Store the provided data as the given type. type is a string. data is a JSON document put(type, id, data) | Overwrite the stored data of the given type and id with the provided data. type is a string. id is a resourceId string. data is a JSON document.

These functions each return a Promise. The get() and post() function Promises resolve to the JSON document requested or added. The put() function Promise resolves to an object with parameters matching the put() args.