• This repository has been archived on 20/Apr/2019
  • Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 11 years ago
  • Updated almost 6 years ago

Reviews

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

Repository Details

Batch request plugin for hapi

bassmaster Logo

Bassmaster makes it easy to combine requests into a single one. It also supports pipelining, allowing you to take the result of one query in the batch request and use it in a subsequent one. The batch endpoint only responds to POST requests.

Build Status

NPM

Lead Maintainer: Christopher De Cairos

Getting Started

Install bassmaster by either running npm install bassmaster in your sites working directory or add 'bassmaster' to the dependencies section of the 'package.json' file and run npm install.

Available options

At this time the options object supports the following configuration:

  • batchEndpoint - the path where batch requests will be served from. Default is '/batch'.
  • description - route description used for generating documentation. Default is 'Batch endpoint'
  • notes - route notes used for generating documentation. Default is 'A batch endpoint which makes it easy to combine multiple requests to other endpoints in a single call.'
  • tags - route tags used for generating documentation. Default is ['bassmaster']
  • auth - If you need the batch route to have authentication

As an example to help explain the use of the endpoint, assume that the server has a route at '/currentuser' and '/users/{id}/profile/'. You can make a POST request to the batch endpoint with the following body and it will return an array with the current user and their profile. Pipelining uses Hoek.reach to retrieve values from request results.

{ "requests": [
    {"method": "get", "path": "/currentuser"},
    {"method": "get", "path": "/users/$0.id/profile"}
] }

The response body to the batch endpoint is an ordered array of the response to each request. Therefore, if you make a request to the batch endpoint that looks like

{ "requests": [
    {"method": "get", "path": "/users/1"},
    {"method": "get", "path": "/users/2"}
] }

The response will look like the following, where the first item in the response array is the result of the request from the first item in the request array.

[{"userId": "1", "username": "bob"}, {"userId": "2", "username": "billy" }]

When making a POST request as part of the batch assign the 'payload' property with the contents of the payload to send.

Optionally you can assign the query as a third property rather than placing it directly into the path. The query property accepts an object that will be formatted into a querystring.

{ "requests": [
    { "method": "get", "path": "/users/1", "query": { "id": "23", "user": "John" } }
] }

If an error occurs as a result of one the requests to an endpoint it will be included in the response in the same location in the array as the request causing the issue. The error object will include an error property that you can interrogate. At this time the response is a 200 even when a request in the batch returns a different code.

More Repositories

1

oz

Web Authorization Protocol
JavaScript
1,532
star
2

postmile

Collaborative list making tool written in Node.js
JavaScript
405
star
3

university

Community learning experiment
JavaScript
374
star
4

lout

API documentation generator
JavaScript
277
star
5

metaphor

Open Graph, Twitter Card, and oEmbed Metadata Collector
JavaScript
230
star
6

tv

Interactive debug console
CSS
186
star
7

hapijs.com

The hapijs.com website
JavaScript
183
star
8

poop

hapi plugin for handling uncaught exceptions
JavaScript
114
star
9

discuss

The "mailing list"
99
star
10

sntp

SNTP client (RFC4330) for node
JavaScript
82
star
11

hapi-contrib

Discussion forum for project contributors
78
star
12

rejoice

hapi.js CLI
JavaScript
64
star
13

penseur

Lightweight RethinkDB wrapper
JavaScript
62
star
14

hapi-auth-hawk

Hawk authentication plugin
JavaScript
47
star
15

scarecrow

Oz authentication plugin
JavaScript
45
star
16

postmile-api

Postmile API Server
JavaScript
43
star
17

reptile

Plugin for creating a REPL
JavaScript
23
star
18

postmile-web

Postmile Web server
JavaScript
18
star
19

mailback

Turns incoming emails to callbacks
JavaScript
15
star
20

catbox-mongodb

MongoDB adapter for catbox (hapi caching)
JavaScript
15
star
21

fireworks

@nodeconf July 4th Fireworks
JavaScript
13
star
22

lobotomy

Replace endpoints with temporary or permanent handlers
JavaScript
5
star
23

bananas

Minimal Loggly hapi plugin
JavaScript
5
star
24

radix62

Convert and parse numbers in base62
JavaScript
4
star
25

require-graphql

Adds GraphQL schema file support to require()
JavaScript
4
star
26

while

Random joi shotcuts
JavaScript
4
star
27

hippocampus

Redis-based object cache with change feed
JavaScript
3
star
28

tarnish

Turn a bunch of buffers into a tar buffer
JavaScript
2
star
29

apiece

Stream-like callback function
JavaScript
2
star
30

feud

Family Fued Website
JavaScript
1
star
31

marker

Cross modules and cross versions shared symbols
JavaScript
1
star