How to set path variable in Tyk?

Hi,

I have an API in Tyk, and it has this listening path like this:

/myapi/{id}

Here, I want to make the {id} as path variable. Is is possible to do it in Tyk?

Like when I call /myapi/1, or /myapi/2, it will proxy to the same URL?

Thanks.

Regards,

Maan Tarng

@maantarng It is very possible. I think you can either use a golang regex in the listen path.

Or you could use the sub or relative path as described in our endpoint designer documentation.

Hope this helps.

Thanks @Olu.

Do you know is it possible to configure path variable in the proxy URL as well?

Like let’s say I want to proxy to this URL: https://domain.com/test/{id}/status

Is it possible also to make this {id} as a path variable in the proxy URL?

Thanks.

I don’t think this is possible to do in the field itself. However, we have a URL Rewrite feature you could take advantage of. Generating the right capture group based on the match pattern would work for your use case.

In summary a combination of URL Rewrite and regex should do the trick.

@Olu

Ok. Thanks. I will try that.

@Olu can we user * or {.*} for any value in path param

example

v1/{id}/test → if id can be anything can i create listening path in tyk as v1/*/test or v1/{.* }/test

Yes, it can. It mentions it in our URL Rewrite docs

thanks it worked thank you