mirror of https://gitee.com/bigwinds/arangodb
Foxx: body and rawBody
This commit is contained in:
parent
f0f95148e0
commit
94c971af9b
|
@ -170,6 +170,9 @@ This is the complete path as supplied by the user as a String.
|
|||
@CLEARPAGE
|
||||
@copydetails JSF_foxx_BaseMiddleware_request_body
|
||||
|
||||
@CLEARPAGE
|
||||
@copydetails JSF_foxx_BaseMiddleware_request_rawBody
|
||||
|
||||
@CLEARPAGE
|
||||
@copydetails JSF_foxx_BaseMiddleware_request_params
|
||||
|
||||
|
|
|
@ -17,9 +17,15 @@ function BaseMiddlewareSpec () {
|
|||
},
|
||||
|
||||
testBodyFunctionAddedToRequest: function () {
|
||||
request.requestBody = "test";
|
||||
request.requestBody = JSON.stringify({test: 123});
|
||||
baseMiddleware(request, response, options, next);
|
||||
assertEqual(request.body(), "test");
|
||||
assertEqual(request.body(), {test: 123});
|
||||
},
|
||||
|
||||
testRawBodyFunctionAddedToRequest: function () {
|
||||
request.requestBody = JSON.stringify({test: 123});
|
||||
baseMiddleware(request, response, options, next);
|
||||
assertEqual(request.rawBody(), JSON.stringify({test: 123}));
|
||||
},
|
||||
|
||||
testParamFunctionReturnsUrlParameters: function () {
|
||||
|
|
|
@ -52,14 +52,28 @@ BaseMiddleware = function () {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn JSF_foxx_BaseMiddleware_request_body
|
||||
/// @brief The superfluous `body` function
|
||||
/// @brief Get the JSON parsed body of the request
|
||||
///
|
||||
/// @FUN{request.body()}
|
||||
///
|
||||
/// Get the body of the request
|
||||
/// Get the JSON parsed body of the request – if you need the raw version, please
|
||||
/// refer to the `rawBody` function.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
body: function () {
|
||||
return JSON.parse(this.requestBody);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn JSF_foxx_BaseMiddleware_request_rawBody
|
||||
/// @brief Get the raw body of the request
|
||||
///
|
||||
/// @FUN{request.rawBody()}
|
||||
///
|
||||
/// The raw request body, not parsed – just a String.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
rawBody: function () {
|
||||
return this.requestBody;
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue