1
votes

What would be the best way to capture responses from APIs and use it as an input to Karate mock? Is this built into Karate framework? Any documentations or suggestions will be appreciated.

At a high level, here is what I want to build.

Generate Data

  1. A scheduled job that can execute a set of API endpoints and capture their responses.
  2. Responses to be saved as json file for each of the endpoints.
  3. Create an Artifact and publish it to a repo, so that its available across teams.

Consume data as Karate Mock/Test Doubles

  1. Developer would download the artifact (json files).
  2. Start the mock server with feature file(s).
  3. The scenarios in the feature files uses the json file to produce the mock response.

Note: Brand new to karate and currently learning/exploring its offerings and capabilities.

Thanks.

1

1 Answers

0
votes

This is a very open-ended question. You can do all of this but you have to write some code. Record-replay is not built into Karate. But yes, you should be able to write some custom code to save responses to a file, there are some interceptor hooks you can look at: Karate: Is there a http-request hook in karate, that gets called automatically after every API call, and whose behaviour I can modify?

And then you can write some mocks that read some local JSON files and shape responses. You will indeed need to do some ramp-up on the framework. Normally teams don't jump straight into mocking like you seem to be doing. Here are the docs: https://github.com/intuit/karate/tree/master/karate-netty