How to use the restify.fullResponse function in restify

To help you get started, we’ve selected a few restify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rajajhansi / aspnetcore-aurelia-tutorial / part6 / modern / nodejs / server / src / contact-manager / bootstrap / restify-application.ts View on Github external
public bootstrap(port: number) {
    this.restifyApplication.use(restify.CORS());
    this.restifyApplication.use(restify.pre.sanitizePath());
    this.restifyApplication.use(restify.acceptParser(this.restifyApplication.acceptable));
    this.restifyApplication.use(restify.bodyParser());
    this.restifyApplication.use(restify.queryParser());
    this.restifyApplication.use(restify.authorizationParser());
    this.restifyApplication.use(restify.fullResponse());

    // configure API and error routes
    this.restifyContactRouter.configApiRoutes(this.restifyApplication);
    this.restifyContactRouter.configErrorRoutes(this.restifyApplication);
    // listen on provided ports
    this.restifyApplication.listen(port, () => {
      console.log("%s listening at %s", this.restifyApplication.name, this.restifyApplication.url);
    });
  }
}
github covcom / 304CEM / labs / 05 RESTful APIs / 01 Simple API / todo / index.js View on Github external
/* import the 'restify' module and create an instance. */
var restify = require('restify')
var server = restify.createServer()

/* import the required plugins to parse the body and auth header. */
server.use(restify.fullResponse())
server.use(restify.bodyParser())
server.use(restify.authorizationParser())

/* import our custom module. */
var lists = require('./lists.js')

/* if we receive a GET request for the base URL redirect to /lists */
server.get('/', function(req, res, next) {
  res.redirect('/lists', next)
})

/* this route provides a URL for the 'lists' collection. It demonstrates how a single resource/collection can have multiple representations. */
server.get('/lists', function(req, res) {
  console.log('getting a list of all the lists')
  /* we will be including URLs to link to other routes so we need the name of the host. Notice also that we are using an 'immutable variable' (constant) to store the host string since the value won't change once assigned. The 'const' keyword is new to ECMA6 and is supported in NodeJS. */
  const host = req.headers.host
github covcom / 304CEM / labs / 05 RESTful APIs / 01 Simple API / restify-api / index.js View on Github external
// Coventry University Findland Visit 2015
// Colin Stephen

// Import modules
// PREREQUISITE: Remember to do "npm install" for both 'restify' and 'nano' modules
var restify = require('restify'); 
var server = restify.createServer();
var nano = require('nano')('http://localhost:5984');

// Set up DB access
// PREREQUISITE: Use CouchDB web interface to create an "articles" database beforehand
var articles = nano.use('articles');

// Configure Restify middleware
server
    .use(restify.fullResponse())
    .use(restify.bodyParser())
 
// Define Article API route endpoints
// TASK: uncomment the middle 3 routes and write their handlers below
server.post("/articles", createArticle);
//server.get("/articles", listArticles);
//server.put("/articles/:id", updateArticle);
//server.del("/articles/:id", deleteArticle);
server.get("/articles/:id", viewArticle);

// Launch the API server
// TASK: Run the server with "node index.js" in the terminal
var port = process.env.PORT || 3000;
server.listen(port, function (err) {
    if (err)
        console.error(err)
github ycombinator / state-machine / restapi / server.js View on Github external
var config = require('config'),
    restify = require('restify'),
    resources = require(__dirname + '/resources')

// Define server
var server = restify.createServer({
  name: 'state-machine-restapi',
  version: '0.0.1'
})

server.use(restify.bodyParser())
server.use(restify.CORS())
server.use(restify.fullResponse())

// Routes
server.post('/v1/state-machines', resources.v1.state_machines.post)
server.get('/v1/state-machine/:id/current-state', resources.v1.state_machine_current_state.get)
server.get('/v1/state/:id', resources.v1.state.get)
server.post('/v1/state-machine/:id/input', resources.v1.state_machine_input.post)

// Start server
server.listen(config.restapi.port, function() {
  console.log('%s listening at %s', server.name, server.url)
})
github joyent / node-workflow / lib / api.js View on Github external
next();
    });
    server.on('after', function (req, res, route, err) {
        if (req.route && !EVT_SKIP_ROUTES[req.route.name]) {
            req.trace.end(req.route.name);
        }
    });

    server.use(restify.acceptParser(server.acceptable));
    server.use(restify.dateParser());
    server.use(restify.queryParser());
    server.use(restify.bodyParser({
        overrideParams: true,
        mapParams: true
    }));
    server.use(restify.fullResponse());

    server.acceptable.unshift('application/json');

    // Return Service Unavailable if backend is not connected
    server.use(function ensureBackendConnected(req, res, next) {
        if (typeof (backend.connected) !== 'undefined' &&
            backend.connected === false) {
            return next(new restify.ServiceUnavailableError(
                'Backend not connected'));
        }

        return next();
    });

    // Write useful x-* headers
    server.use(function (req, res, next) {
github covcom / 304CEM / 2015 / 2015 05 RESTful APIs / 01 Simple API / api_example / api.js View on Github external
var restify = require('restify')
var server = restify.createServer()

/* import the required plugins to parse the body and auth header. */
server.use(restify.fullResponse())
server.use(restify.bodyParser())
server.use(restify.authorizationParser())

var recipes = ['Recipe 1: milk, eggs, flour', 'Recipe 2: eggs, ham, bread'];

server.get('/recipes', function (request, response) {
    // this is where you access the DB OR access an external API for data
    var data = recipes;
    var dataJson = JSON.stringify(data);
    response.setHeader('content-type', 'application/json');
    response.send(200, dataJson);
    response.end();
});

server.post('/recipes', function (request, response) {
    const body = request.body;
github covcom / 304CEM / Lab Demos / week08 / before / index.js View on Github external
'use strict'

const restify = require('restify')
const server = restify.createServer()

const googleapi = require('./modules/booksquery')
const favourites = require('./modules/favourites')
const authorization = require('./modules/authorisation')
const users = require('./modules/users')

server.use(restify.fullResponse())
server.use(restify.queryParser())
server.use(restify.bodyParser())
server.use(restify.authorizationParser())

server.get('/booksearch', googleapi.doBookSearch)

server.get('/favourites', authorization.authorize, favourites.list)  // get a list of all favs
server.post('/favourites', authorization.authorize, favourites.validate, favourites.add)  // add a new fav
server.get('/favourites/:id', authorization.authorize, favourites.get)  // get details of a particular fav using id
server.put('/favourites/:id', authorization.authorize, favourites.validate, favourites.update)  // update details of existing fav using id
server.del('/favourites/:id', authorization.authorize, favourites.delete)  // delete existing fav using id

server.post('/users', users.validateUser, users.add)  // add a new user to the DB (pending confirmation)
server.post('/users/confirm/:username', users.validateCode, users.confirm)  // confirm a pending user
server.del('/users/:username', authorization.authorize, users.delete)  // delete a user
github akveo / chernika-server / api / api.js View on Github external
module.exports.init = function () {
  var server = restify.createServer();
  server
    .use(restify.fullResponse())
    .use(restify.bodyParser())
    .use(restify.queryParser());

  chatApi.init(server.server);

  server.on('MethodNotAllowed', CORSPolicy.unknownMethodHandler);

  server.post("/user", UserController.login, AuthPolicy.login);

  server.use(AuthPolicy.checkSession);
  server.get("/user/confirmPolicy", UserController.confirmPolicy);
  server.get("/user", UserController.find);
  server.post("/user/logout", UserController.logout);
  server.get("/user/settings", UserController.getSettings);
  server.put("/user/settings", UserController.updateSettings);
  server.put("/user/activity", UserController.updateActivity);
github markusthoemmes / pinplot / backend / index.js View on Github external
if (!err && res.statusCode == 200) {
    	var data = JSON.parse(body);

    	var pageId;
    	for(pageId in data.query.pages) break;

    	var extract = data.query.pages[pageId].extract.match(/<p>(.*?)&lt;\/p&gt;/g)[0];
	}
});

var server = restify.createServer({
	name: 'StoryMapper',
});

server
	.use(restify.fullResponse())
	.use(restify.bodyParser());

server.get('/book/:id', function(req, res, next) {
	res.contentType = 'json';
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "X-Requested-With");

	var db = mongojs('storymapper', ['books']);

	if(req.params.id === '') {
		db.books.find(function(err, docs) {
	    	res.send(docs);
		});
	}
	return next();
});</p>
github gustavohenrique / gh1 / server / nodejs / src / app.js View on Github external
function createServer() {
    var siteService = services.Site;
    var userService = services.User;

    var server = restify.createServer({ name: 'GH1' });

    server
        .use(restify.bodyParser())
        .use(restify.gzipResponse())
        .use(restify.CORS())
        .use(restify.queryParser())
        .use(restify.fullResponse())
        .use(restify.throttle({
            burst: 100,
            rate: 50,
            ip: true
        }));

    route
        .use(server)
        .jwt({
            secretOrPrivateKey: JWT_SECRET,
            cors: true,
            allwaysVerifyAuthentication: false,
            callback: function (req, next, decoded) {
                if (decoded) {
                    req.user = decoded;
                    next();