loopbackio / loopback-connector-rest

Connect Loopback to a REST API
http://loopback.io/doc/en/lb2/REST-connector.html
Other
75 stars 81 forks source link

REST Connector variables cannot contain object string in the template #141

Closed jeemok closed 4 years ago

jeemok commented 4 years ago

Based on the example on https://loopback.io/doc/en/lb3/REST-connector.html

{
  "template": {
    "method": "POST",
    "url": "http://localhost:3000/{p}",
    "headers": {
      "accept": "application/{format}"
    },
    "query": {
      "x": "{x}",
      "y": 2
    },
    "body": {
      "a": "{a:number}",
      "b": "{b=true}"
    }
  },
  "functions": {
    "myOp": [
      "p",
      "x",
      "a",
      {
        "name": "b",
        "source": "header"
      }
    ]
  }
}

and I have the following template like this (simplified):

{
  "template": {
    "method": "POST",
    "url": "http://localhost:3000/myEndPoint",
    "headers": {
      "accept": "application/json"
    },
    "body": "{data}"
  },
  "functions": {
    "myOp": ["data"]
  }
}

I have realized if my body contains the object literal {example}, it will have some weird behavior

For example: data is

{ "name": "my name is {test}" }

and this is what I receive in another end:

{ "name": "my name is my name is {test}" }

Seems like a bug, or could it be intended but undocumented (I couldn't find any resources mentioning this). Is there a way that I can remain the original text while using the template variables?

Additional Info:

package.json

    "loopback": "^3.26.0",
    "loopback-boot": "^2.28.0",
    "loopback-component-explorer": "^6.4.0",
    "loopback-component-storage": "^3.6.2",
    "loopback-connector-mongodb": "^4.2.0",
    "loopback-connector-rest": "^3.4.1",
    "loopback-connector-soap": "^5.0.0",