0.2.20 • Published 6 years ago

cheese-toastie v0.2.20

Weekly downloads
4
License
ISC
Repository
github
Last release
6 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

6 years ago

0.2.19

7 years ago

0.2.18

7 years ago

0.2.17

7 years ago

0.2.16

7 years ago

0.2.15

7 years ago

0.2.14

7 years ago

0.2.13

7 years ago

0.2.12

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago