dotronglong / faker

A fake api server built in Java
38 stars 6 forks source link

How can I use the request data in the response? #38

Closed yarkovaleksei closed 1 year ago

yarkovaleksei commented 1 year ago

curl -i htt://localhost:3030/test?id=123

{
  "request": {
    "method": "get",
    "path": "^\/test(.*)$"
  },
  "response": {
    "statusCode": 200,
    "headers": {
      "content-type": "application/json; charset=utf-8"
    },
    "body": {
      "id": "{{request.query.id}}", // 123
      "displayName": "#random:name:male=true#"
    }
  }
}

curl -i htt://localhost:3030/test/123

{
  "request": {
    "method": "get",
    "path": "/test/:id"
  },
  "response": {
    "statusCode": 200,
    "headers": {
      "content-type": "application/json; charset=utf-8"
    },
    "body": {
      "id": "{{request.path.id}}", // 123
      "displayName": "#random:name:male=true#"
    }
  }
}
dotronglong commented 1 year ago

Hi @yarkovaleksei I don’t think I understand your question, would you mind to help me with more info?

yarkovaleksei commented 1 year ago

How to access the request object in order to use the data from it in the response? I looked at the source of the project and I see that only the data about the response is transferred there, for example here: https://github.com/dotronglong/faker/blob/master/src/main/kotlin/com/dotronglong/faker/contract/Plugin.kt

Do you plan to improve this functionality?

dotronglong commented 1 year ago

Did you manage to take a look over this page https://github.com/dotronglong/faker/wiki/Plugins? Perhaps it somehow solves your concern. If it isn’t, would you mind to suggest a prototype of your idea in explanation then I will try to look into it. I would love if you want to contribute code as well then you can raise a PR.

yarkovaleksei commented 1 year ago

Yes, I read the plugin documentation, but this functionality is not there. And unfortunately, I just started learning kotlin in order to submit a pull request. Maybe later))