Skip to content

Instantly share code, notes, and snippets.

@jrdn91
Created November 14, 2017 14:22
Show Gist options
  • Save jrdn91/73f721482cf826218a5fc13a6bd23f8e to your computer and use it in GitHub Desktop.
Save jrdn91/73f721482cf826218a5fc13a6bd23f8e to your computer and use it in GitHub Desktop.
JSONAPI Server Custom Handler
// RESOURCES/PRINT.JS
var jsonApi = require("jsonapi-server");
var printHandler = require("../handlers/printHandler.js");
let PrintHandler = new printHandler();
jsonApi.define({
resource: "print",
handlers: PrintHandler,
searchParams: {
tags: jsonApi.Joi.string()
},
attributes: {
tags: jsonApi.Joi.string()
}
});
// HANDLERS/PRINTHANDLER.JS
'use strict'
const PrintHandler = module.exports = function PrintHandler () {
}
/**
Handlers readiness status. This should be set to `true` once all handlers are ready to process requests.
*/
PrintHandler.prototype.ready = false
/**
initialise gets invoked once for each resource that uses this hander.
In this instance, we're allocating an array in our in-memory data store.
*/
PrintHandler.prototype.initialise = function (resourceConfig) {
this.ready = true
}
/**
Search for a list of resources, given a resource type.
*/
PrintHandler.prototype.search = function (request, callback) {
const self = this
console.log(request.route.query)
return callback(null, {
message: 'hello world'
}, 1)
}
/**
Find a specific resource, given a resource type and and id.
*/
PrintHandler.prototype.find = (request, callback) => {
// Return the requested resource
return callback(null, {
message: 'hello world'
})
}
/**
Create (store) a new resource given a resource type and an object.
*/
PrintHandler.prototype.create = (request, newResource, callback) => {
// Return the newly created resource
return callback(null, {
message: 'hello world'
})
}
/**
Delete a resource, given a resource type and and id.
*/
PrintHandler.prototype.delete = function (request, callback) {
return callback()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment