• This repository has been archived on 03/Mar/2023
  • Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    JavaScript
  • Created over 12 years ago
  • Updated about 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A declarative HATEOAS API crawler for node.js

hyperspider

Build Status

hyperspider is a declarative HATEOAS API crawler for node.js. Give it a list of url patterns, and it will recursively crawl your hypertext HTTP API, streaming back every matching endpoint.

hyperspider is great for folks that want to create clean, granular, and self-documenting hypertext APIs, but avoid the latency of remotely fetching hundreds of tiny HTTP resources.

Example

Let's say you had a Twitter clone with a hypertext JSON API, including the following two sample endpoints:

GET /users/:id (fetch a user)

{
  "href": "/users/jedschmidt",
  "name": "Jed Schmidt",

  "location":  { "href": "/japan/tokyo" },
  "updates":   { "href": "/users/jedschmidt/updates" },
  "following": { "href": "/users/jedschmidt/following" },
  "followers": { "href": "/users/jedschmidt/followers" }
}

GET /users/:id/following (fetch the users a user is following)

{
  "href": "/users/jedschmidt/following",
  "items": [
    { "href": "/users/janl" },
    { "href": "/users/cramforce" },
    { "href": "/users/hblank" },
    { "href": "/users/theophani" }
  ]
}

To create a single following-detailed resource so that API consumers don't have to make a separate HTTP call for each resource, use hyperspider like this:

var hyperspider = require("hyperspider")

var options = {
  host: "mytwitterclone.biz",
  path: [
    "/users/jedschmidt",
    "/users/jedschmidt/following",
    "/users/*"
  ]
})

hyperspider(options, function(err, data) {
  // data is an array with the result entities of 6 endpoints:
  // 1. /users/jedschmidt
  // 2. /users/jedschmidt/following
  // 3. /users/janl
  // 4. /users/cramforce
  // 5. /users/hblank
  // 6. /users/theophani
})

See the tests for a working example.

Installation

Use npm to install hyperspider:

npm i hyperspider

API

req = hyperspider(options, [callback])

options: An object containing the same options as for node's http.request method, with one exception: path can be any of the following:

  • a normal url path, such as /users
  • a function that takes a path and returns a boolean
  • a RegExp that matches a path
  • a wildcard url path to turn into a RegExp, with * replaced by [^/]+ and ** replaced by .*?
  • an array containing any of the above

Note that path must contain at least one normal url path to serve as the starting point for the crawl.

callback(err, data): Buffers the event stream into a single callback. err is null if no errors occurred, and otherwise the first error emitted, with subsequent errors available from the next property of the error. data is an array of responses, one for each successful HTTP call. Omit this to listen for a stream of events.

req.extract (or hyperspider.prototype.extract)

This method takes a single argument, an HTTP response. Override this before adding listeners to customize how hyperspider should extract urls from each resource. By default, the response body is parsed into JSON, extracting the value of every nested href property, but you could roll your own, such as parsing Link headers, etc.

More Repositories

1

140bytes

Once a tweet-sized, fork-to-play, community-curated collection of JavaScript.
HTML
1,031
star
2

lave

eval in reverse: stringifying all the stuff that JSON.stringify won't
JavaScript
896
star
3

fab

a modular async web framework for node.js
JavaScript
732
star
4

browserver-client

เทด A node.js HTTP server in your browser เทด
JavaScript
638
star
5

authom

A zero-dependency mutli-service authentication tool for node.js
JavaScript
401
star
6

browserver-node

เทด Browserver proxy for node.js เทด
JavaScript
333
star
7

domo

Markup, style, and code in one language.
JavaScript
308
star
8

certbot-route53

Helping create Let's Encrypt certificates for AWS Route53
Shell
175
star
9

kibi

a client-side web framework in 1,024 bytes
JavaScript
144
star
10

dynamo

DynamoDB client for node.js
JavaScript
141
star
11

building-brooklynjs

My story of how we built BrooklynJS.
136
star
12

rndr.me

an HTTP server that uses PhantomJS to render HTML
JavaScript
133
star
13

weenote

A quick/dirty/tiny tool for creating simple Takahashi-style presentations.
HTML
119
star
14

sheet-down

A Google Spreadsheet implementation of leveldown
JavaScript
108
star
15

cookie-node

signed cookie functionality for node.js
JavaScript
82
star
16

config-leaf

Hide your sensitive node.js bits in plain sight.
JavaScript
53
star
17

sajak

Simple Authenticated JSON API Kit
JavaScript
33
star
18

dynamo-down

A leveldown API implementation on AWS DynamoDB
JavaScript
31
star
19

localhose

Hose your hosts file for easier local web development
JavaScript
29
star
20

browserver.org

The code for the browserver.org web site.
CoffeeScript
29
star
21

emit

A reactive toolkit for JavaScript
JavaScript
29
star
22

dynamo-client

A low-level client for accessing DynamoDB from node.js
JavaScript
28
star
23

osx-browser-vm

Evaluate JavaScript in local OS X browsers
JavaScript
28
star
24

dynamo-streams

A stream-flavored wrapper for the AWS DynamoDB JavaScript API
JavaScript
25
star
25

wc-jsx-runtime

A JSX transform for Web Components
JavaScript
23
star
26

tmpl-node

a template module for node.js
JavaScript
20
star
27

esbuild-plugin-http-fetch

An esbuild plugin that resolves http(s) modules
JavaScript
19
star
28

skeyma

A JavaScript parser & serializer for {key, value} objects & streams
JavaScript
18
star
29

browserver-router

A platform-agnostic router for HTTP listeners that follow the node.js spec
JavaScript
18
star
30

cfn-api-gateway-custom-domain

API Gateway custom domains as CloudFormation resources, backed by Let's Encrypt
JavaScript
18
star
31

alReady.js

a terse, embeddable, and cross-browser domReady implementation
JavaScript
17
star
32

electric-objects

A node.js API for the Electric Objects EO1 frame
JavaScript
17
star
33

monot

Unique JavaScript dates
JavaScript
15
star
34

google-worksheet-stream

A streaming interface for Google Spreadsheets
JavaScript
14
star
35

dinkumise

Keep ya JavaScripts Dinki-di!
11
star
36

pbsb

getters/setters and pub/sub in one tiny javascript function
JavaScript
11
star
37

twil-eo

Using Twilio, AWS, and Electric Objects to create an MMS-powered family photo frame.
JavaScript
10
star
38

textpanda

web-based text shortcuts for the lazy
JavaScript
8
star
39

diff-stream2

Merges multiple sorted streams into a diffed tuple stream
JavaScript
7
star
40

namedrop

minification for DOM-heavy code
JavaScript
7
star
41

eartag

Tag browsers like farmers tag livestock
JavaScript
7
star
42

autorequire

small module for autorequiring. warning: MAGIC!
JavaScript
6
star
43

sort-stream2

Array.prototype.sort for streams
JavaScript
6
star
44

dynamo-sync

Differential data synchronization for Amazon's DynamoDB
6
star
45

google-oauth-jwt-stream

A readable stream of OAuth access tokens for use with Google APIs
JavaScript
6
star
46

dom-jsx-runtime

A tiny library that turns JSX into DOM operations
JavaScript
6
star
47

node-lacrosse

A node.js streaming API for Lacrosse Alert sensors
JavaScript
6
star
48

abstract-stream-leveldown

A stream-based abstract prototype matching the LevelDOWN API
JavaScript
5
star
49

gist-in-time

a stylesheet for displaying github gist metadata on hover
5
star
50

typd.in

a web-based input method editor for japanese
JavaScript
4
star
51

esbuild-plugin-eval

An esbuild plugin that evaluates a module before importing it
JavaScript
4
star
52

one-character-identifiers

every javascript identifier that fits in a character
JavaScript
4
star
53

jed.is

personal web site
3
star
54

domogenize

Turn static HTML and CSS into declarative JavaScript
JavaScript
3
star
55

ramendan

CoffeeScript
3
star
56

census-topologies

Topologies from the U.S. Census Bureau
Shell
3
star
57

20x20

a simple pecha kucha timer optimized for my iPhone
JavaScript
3
star
58

utfn

a test of the utf-n encoding
3
star
59

esbuild-plugin-bundle

An esbuild plugin that bundles modules before importing them
JavaScript
2
star
60

deno_bundle

A temporary workaround to support bundling with sourcemaps in Deno
JavaScript
2
star
61

ordered-kv-tuple-stream

Aligns multiple ordered k/v readable streams into one
JavaScript
2
star
62

tuple-stream2

Aligns multiple readable object streams into one stream
JavaScript
2
star
63

esbuild-plugin-deno-http

An esbuild plugin that uses Deno to resolve and cache HTTP modules
JavaScript
2
star
64

esbuild-plugin-env

An esbuild plugin that exports the current environment as a module
JavaScript
2
star
65

deno-file-system-access-api

File System Access API for Deno
JavaScript
1
star
66

level-sync

One-way sync for levelup data stores
JavaScript
1
star
67

abevigoda

Abe Vigoda as a Service
JavaScript
1
star
68

esbuild-plugin-view-source

An esbuild plugin that enables built modules to be imported as source
JavaScript
1
star