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

diaspora-server

v0.1.0

Published

A webserver module for Diaspora

Downloads

8

Readme

Diaspora-server

A package to add RESTful APIs to Express with Diaspora

Fancy badges: Build Status Dependency Status Maintainability Test Coverage
npm npm version GitHub commit activity the past year license

Getting started:

Installation:

In order to run Diaspora Server, you need to install both Diaspora Server & Diaspora itself

npm i diaspora-server diaspora

Configuration:

const Diaspora = require( 'diaspora' );
const DiasporaServer = require( 'diaspora-server' );
const app = require( 'express' )();

/* Configure Diaspora first: create your data sources, declare your models, etc... */
Diaspora.createNamedDataSource( /* ... */ );
Diaspora.declareModel( 'PhoneBook', /* ... */);

app.use( '/api', DiasporaServer({
	models: {
		PhoneBook: {
			singular:    'PhoneBook',
			plural:      'PhoneBooks',
			middlewares: { /* ... */ },
		},
	},
}));

In the hash models, you can select which models you want to expose. You can use regular expressions, minimatch or plain text matching:

app.use( '/api', DiasporaServer({
	models: {
		'/ab?c\\d+/': {} // Regex, will match ac1, abc1, abc09
		'Qux*':       {} // Minimatch, will match Qux, QuxFoo, etc etc
		PhoneBook:    {} // Plain text matching
	},
});

In your model configuration, you can use following middlewares:

| Action | Middleware functions (singular API) | Middleware functions (plural API) | |---------|-------------------------------------|-----------------------------------| | Insert | post, insert, insertOne | post, insert, insertMany | | Find | get, find, findOne | get, find, findMany | | Update | patch, update, updateOne | patch, update, updateMany | | Replace | put, update, replaceOne | put, update, replaceMany | | Delete | delete, deleteOne | delete, deleteMany |

Each middleware will be called as a standard Express middleware (eg with req, res & next). You can use them to customize the behavior of Diaspora Server.

Getting further:

Diaspora Server uses the same Diaspora module than your app, both sharing models & the web server.

For each requests below, the server may respond:

  • 204 No Content if the operation didn't returned an entity or the set is empty.
  • 400 Bad Request if the parsing of the query failed
  • 404 Not Found if using singular API with ID: /api/foo/66b72592-b1e2-4229-82b2-c94b475c9135

| Action | HTTP Verb | Additionnal possible responses | |------------------|-----------|------------------------------------------------------------------------------------------------------------------------| | Insert | POST | 201 Created on success, 400 Bad request if validation failed | | Find | GET | 200 OK on success | | Update (diff) | PUT | 200 OK on success, 400 Bad request if validation failed, 405 Method Not Allowed if no where clause | | Update (replace) | PATCH | 200 OK on success, 400 Bad request if validation failed, 405 Method Not Allowed if no where clause | | Delete | DELETE | 204 No Content if no errors occured |

The documentation will be available at https://diaspora-server.ithoughts.io/

Inspired by this tutorial

Todo

  • API Maps with OPTION verb
  • SOAP support?