Step 3: Simulate custom scenarios

Intro

In this step, we will allow the backend application to process the simulation requests from end users:

  1. Accept a scenario from the user.

  2. Run the simulation.

  3. 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:

FastExperimentController.java, new method
@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:

  1. URL: http://localhost:8080/runExperiment

  2. Request type: POST

  3. Request body type: raw, JSON

  4. 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:

POST request results