GithubHelp home page GithubHelp logo

Comments (14)

tomakehurst avatar tomakehurst commented on July 19, 2024 1

Additionally there's the option of a really basic templating engine (e.g. StringTemplate) so that you can replace properties:

{
  "myHeaderValue": '$$request.headers.X-My-Header$$'
}

from wiremock.

pmendelski avatar pmendelski commented on July 19, 2024 1

IMHO the second option is much easier/better.

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

Unfortunately this isn't possible with WireMock at the moment.

I believe SOAP UI's mock REST server will allow you to do this via Groovy scriptlets if that's any help.

from wiremock.

illaz avatar illaz commented on July 19, 2024

Thank you for the quick answer and the hint.
Even if I prefer WireMock, I think, I have to use SOAP UI in this case.

from wiremock.

pmendelski avatar pmendelski commented on July 19, 2024

Do you plan to include this feature in wiremock 2.0?

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

You can already do it by implementing a response transformer extension, albeit with a little work.

I'm considering some options here - perhaps extensions that ship with WireMock but aren't activated by default to e.g. execute Javascript or template the response. Trying to figure out how to do it without adding too much bloat.

from wiremock.

pmendelski avatar pmendelski commented on July 19, 2024

Thanks for quick update. I would appreciate another comment on this issue when you figure it out.

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

I'll do my best to remember :-)

Which approach are you more interested in: scripted or templated?

from wiremock.

pmendelski avatar pmendelski commented on July 19, 2024

Thanks for goodwill ;-)

Both approaches are interesting. Could you give a basic mapping example of each of them?
Scenario is simple. Lets reuse a json object property from request body in the response.

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

I was thinking of adding an extension that called a user-supplied Javascript function to determine the response e.g.

// Copy the request body into the response body
function transformResponse(request, responseBuilder) {
  responseBuilder.body(request.body);
}

from wiremock.

pmendelski avatar pmendelski commented on July 19, 2024

In most cases I would go with the second option. I believe that first one would be useful in some edge cases.

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

I like the 1st one because a) there's already a JS engine available in the JVM, and b) JSON is easy in JS.

But the 2nd is probably easiest when you just want to inject one or two values, which might be the majority case.

from wiremock.

pmendelski avatar pmendelski commented on July 19, 2024

A "real life" example. In my team we have an agreement that every successful POST request will result in a 201 response with a Location header and body that will contain created entity. In most cases the response body is similar to the request body but enriched with few fields (like an id).

In this case perfect solution would be to inherit request body and add missing fields.

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

OK, thanks for the input. Will consider that when I get round to doing this.

from wiremock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.