Step 3: Simulate custom scenarios
Intro
In this step, we will allow the backend application to process the simulation requests from end users:
-
Accept a scenario from the user.
-
Run the simulation.
-
Return the results of the simulation back to the user.
Our backend application is already capable of running a simulation (item #2) for embedded scenarios and returning simulation results (item #3). One thing left is to add the ability to accept user scenarios (item #1).
Update the ExperimentController
Add a new method to the FastExperimentController
class:
@PostMapping(value = "/runExperiment", consumes = "application/json", produces = "application/json")
public SimulationResultsDTO runExperiment(@RequestBody ScenarioDTO scenarioDTO) {
Scenario scenario = scenarioMapper.readFromDTO(scenarioDTO);
return fastExperimentService.runExperiment(scenario);
}
Check the result
You will need a tool such as Postman or Curl to send POST requests.
Start the backend application. In Postman (or other tool of your choice) send a request:
-
Request type: POST
-
Request body type: raw, JSON
-
Request body: <paste here the contents of any scenario file from the
src/main/resources/scenarios
folder>
Here is what you should get in response:
