Hi Team, In the request header, is there a possib...
# help
s
Hi Team, In the request header, is there a possiblity in wiremock to fetch the dynamic data. For eg. "Authorization" : {{dynamic-data}} Is this is the approach? There is an api, which will consist this Authorization header, in this how dynamic data can be fetched.
b
Hey @Shruti Mishra , I think what you’re looking for is response templating (or in other words, reusing request values in the response). Have a look at https://wiremock.org/docs/response-templating/ and more specifically at using {{request.headers.Authorization}}
s
Hi @Bas Dijkstra, in the request header wanted to validate the value...based upon that required to have a response. For eg: In the request header "Abc" : {{dynamic value(base 64 encoded)}} Have to decode that value. Apply the validation and check if that decoded value contains certain chars. If yes render 200 response else 400 response. Here I dont wanted to reuse the value in response, instead have to apply validation and toggle the success and failure response. Thanks.
@Bas Dijkstra Can you please provide me some example related to this.
b
Ah, that’s more clear. You can do that with a request filter. Here’s an example from my open source WireMock workshop that does something very similar: https://github.com/basdijkstra/wiremock-workshop/blob/main/src/test/java/answers/extensions/BasicAuthRequestFilter.java See https://wiremock.org/docs/extending-wiremock/ for more information on extending WireMock.
All you need to do is change the logic to check the Authorization header value.
s
Thanks @Bas Dijkstra for the help.
🙌 1
b
Let me know when you’ve made it work
s
Sure