smollweide / node-mock-server

File based Node REST API mock server
MIT License
255 stars 65 forks source link

Question: POST body with "params" key #74

Closed StoyanKostov closed 7 years ago

StoyanKostov commented 7 years ago

Hello,

I have a POST request with a body like:

{
  "method": "DEL",
  "params": {
    "application": "LOANS",
    "record_id": "LD111111111111"
  }
}

My response should be something like:

{
    "record_id": "<%-getId(params);%>",
    "operation_successful": true
}

My getId function is:

....
getId: function ( params ) {
        return params.application;
    }
....

It seems to me that "params" is a reserved word for GET url parameters. So "params" has a value of empty object {} in getId function. How can I access "application" value in getId?

Best regards!

smollweide commented 7 years ago

Hello @StoyanKostov, thanks for this report. You are right "params" is reserved for path params. Could be possible to provide the data in a wrapped object like:

{
  "body": {},
  "params": {},
  "query": {},
  "faker": {},
  ...
}

Best

smollweide commented 7 years ago

Fix was published as 0.19.0-alpha. Run npm install node-mock-server@0.19.0-alpha and change your getId function:

....
getId: function ( params ) {
        return body.params.application;
    }
....