apimastery / APISimulator

API Simulator - configuration-driven tool for modeling and running of API simulations
https://apisimulator.io
3 stars 1 forks source link

Returning data from multiple files stored in the simulation #18

Open pautib opened 2 years ago

pautib commented 2 years ago

Recently, I added API Recorder as an option for a simulation a customer asked for some months ago. Now, they are asking whether the information stored in the *.rec files with the history of requests and responses could be retrieved as an API, specifying for instance the range of dates with the transactions to be displayed. They say that for test automation purposes it would be easier for them to get this information as an API rather than reading or parsing the files.

I searched the documentation and all the examples involving returning data from files only allow you to explicitly select one file, like here: https://apisimulator.io/docs/1.7/standalone-api-simulator/response-http-codec.html#large-file-download-example

In the Scripting section, I don't see any example or comment saying that it is possible to retrieve the information from multiple files in a simulation folder and parse them on the response. Is it something possible to do currently? If not, are you considering the implementation?

Thank you in advance

apisim commented 2 years ago

Hi @pautib

The *.rec files contain the raw HTTP requests and responses (for HTTP/1.x) as they were captured "on the wire". There currently isn't something built into API Simulator to parse them out at, say, startup time.

A lot can be accomplished with scripting, indeed. I'm not sure I understand what is the ask, though. Could you elaborate a bit on "...retrieve the information from multiple files in a simulation folder and parse them on the response"?

pautib commented 2 years ago

Hi @apisim

thank you for answering back. I wanted to ask if scripting could allow me to use I/O Groovy functions to get the raw information from *.rec files, concatenate them, and return them back to the simlet to display it as a raw text response. If I could do this, I could make an extra simlet on the simulation to retrieve the history of transactions by date and check the files whose titles match the dates I specified as URI parameters.

apisim commented 2 years ago

There shouldn't be limitations in using anything from Groovy.

Just to keep in mind that in some cases the Groovy functionality may be in a separate JAR. An example is groovy-json-x.y.x.jar. Such JARs can be added to the API Simulator installation's lib directory, or to a lib directory inside the simulation's folder. This way, the JARs will be on the classpath and will get picked up. Perhaps it will be best if the version of those JARs matches the version of the version of Groovy included in API Simulator's lib folder. For example, API Simulator v1.10 uses groovy-3.0.10.jar, so groovy-json should be groovy-json-3.0.10.jar.