0.2.20 • Published 8 years ago

cheese-toastie v0.2.20

Weekly downloads
4
License
ISC
Repository
github
Last release
8 years ago

CheeseToastie ( 🧀 🍞 )

CheeseToastie is a NodeJS library that makes it really easy to build well thought out APIs based on Swagger JSON files.

Features

  • API defined via a JSON file (Swagger-like format)
  • Validation of parameters (type, required, etc)
  • Ability to include an authentication function that will run prior to secured endpoints being hit
  • Uses ExpressJS as an underlying library

JSON File

To use this library, you'll need to setup a JSON Swagger file that defines your API (endpoints, parameters, etc). More examples on this coming soon.

Quick Start

var express = require("express");
var bodyParser = require('body-parser');

var cheeseToastie = require("cheese-toastie");

var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Start the CheeseToastie API
cheeseToastie.start(__dirname, app);

// Start the server
var server = app.listen(process.env.PORT || '8080', function () {
  console.log("You're ready to go 🧀 🍞");
});

Authenticating Requests

You can mark routes in your JSON file as requiring authentication like this:

...
"authRequired": true,
...

You must then provide an authenticator function to the CheeseToastie library that will run against authenticated requests and return either a user object or null (if the user is not logged in/their token is not valid).

cheeseToastie.setAuthenticatorMethod(function(token, callback) {
  // Silly example, normally you'd be decoding a JSON Web Token
  if (token && token == "1234") {
    return callback({name: "Daryl"});
  }

  return callback(null);
});

cheeseToastie.start(__dirname, app);

Callback options

When you return a callback to Cheese Toastie it should be of the following format:

return callback(err, data, redirect, options)
  • err - An error, if present
  • data - The data response, by default this should be in JSON
  • redirect - An optional redirect URL
  • options - An optional object that contains
0.2.20

8 years ago

0.2.19

9 years ago

0.2.18

9 years ago

0.2.17

9 years ago

0.2.16

9 years ago

0.2.15

9 years ago

0.2.14

9 years ago

0.2.13

9 years ago

0.2.12

9 years ago

0.2.11

10 years ago

0.2.10

10 years ago

0.2.9

10 years ago

0.2.8

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago