From 96aa1d912978a742f5d8a22f09207eeb80e8c9ea Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Wed, 20 Apr 2016 17:18:43 +0200 Subject: [PATCH] Add req.json --- js/server/modules/@arangodb/foxx/router/request.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/server/modules/@arangodb/foxx/router/request.js b/js/server/modules/@arangodb/foxx/router/request.js index 91ebdfaaf1..89f3c74147 100644 --- a/js/server/modules/@arangodb/foxx/router/request.js +++ b/js/server/modules/@arangodb/foxx/router/request.js @@ -44,6 +44,7 @@ module.exports = class SyntheticRequest { this.pathParams = {}; this.queryParams = querystring.decode(this._url.query); this.body = getRawBodyBuffer(req); + this.rawBody = this.body; const server = extractServer(req, context.trustProxy); this.protocol = server.protocol; @@ -145,6 +146,13 @@ module.exports = class SyntheticRequest { return this._raw.database; } + json() { + if (!this.rawBody) { + return undefined; + } + return JSON.parse(this.rawBody.toString('utf-8')); + } + params(name) { if (hasOwnProperty.call(this.pathParams, name)) { return this.pathParams[name];