dreamhead / moco

Easy Setup Stub Server
MIT License
4.37k stars 1.08k forks source link

Use URI path parameters on the response template #325

Closed wapcrazut closed 1 year ago

wapcrazut commented 2 years ago

Is it possible to use URL parameters in path and insert them in the response template, as URL queries?

For some mocks, I see the need to insert values coming from the URL path.

For example:

Maybe something like the following:

    {
        "request": {
            "uri": {
                "match": "/v1/test/.*/example"
            },
            "method": "get",
        },
        "response": {
            "status": 200,
            "text": {
                "template": "{$req.uri.param[0]}"
            },
            "headers": {
                "Content-Type": "application/json"
            }
        }
    },

Thanks.

wapcrazut commented 2 years ago

Hello @dreamhead, sorry to ping but I was wondering if you could have any idea if this is already implemented or if this needs some work. If that's the case, could you point me to where to start at? Thanks.

dreamhead commented 2 years ago

This feature is not supported for now.

I do want to implement this feature, that's like Spring RequestMapping parsing, as following:

{
        "request": {
            "uri": {
                "path": "/v1/test/{foo-id}/example"
            },
            "method": "get",
        },
        "response": {
            "status": 200,
            "text": {
                "template": "{$req.uri.path.foo-id}"
            },
            "headers": {
                "Content-Type": "application/json"
            }
        }
}
wapcrazut commented 2 years ago

@dreamhead That seems pretty good, do you have plans on when to implement this? I would like to help but I'll need some guidance on how to extend Moco's functionality.

dreamhead commented 2 years ago

@wapcrazut Feel free to commit PR. I'll help you extend Moco.

dreamhead commented 1 year ago

@wapcrazut Your feature request has been included in release 1.4.0. https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md#path-2

wapcrazut commented 1 year ago

@dreamhead Awesome!! many thanks for the hard work you guys put into this project 🚀