Marcio's API - Kuckelkorn/bubble-machine GitHub Wiki

Marcio's API

The API

Basic functions

Marcio the researcher here at the HvA asked us to write the frontend for his model. He made his own API with a socket connection for us to work with. The API has some basic functions, it starts off with creating a session by writing a POST request, then it is possible to make a GET request to see the data of the session. To increase the steps, you once again make a POST request increasing the steps and a GET request to receive the data. If you want to reset the current session, you make a PUT request.

const fetchDataFromAPI = async (method, url) => {
  if (method === 'PUT' || method === 'POST') {
    fetch(url, {
      method: `${method}`
    })
  } else {
    const response = await fetch(url, {
      method: `${method}`,
      mode: 'cors'
    })
    const data = response.json()
    return data
  }
}

Because of some errors, we need to specify the mode to CORS for a GET request. Which isn't necessary for the POST and PUT requests.

Next phase

In the final week, Marcio updated his API, which can take parameters when creating a simulation. So when creating a session, you send the parameters with it, in an object form.

Below is an example of an example session creation

{
  "name": "session_1",
  "number_of_agents": "102",
  "num_friends": "20",
  "num_steps_per_day": "1",
  "num_items_per_day": "20",
  "max_num_item_links": "20",
  "num_exposed_items_person_day": "20",
  "latitude_acceptance": "0.3",
  "sharpness": "13",
  "probability_post_social_net": "0.3",
  "user_behaviour": "RS_Social_Network",
  "rs_alg": "2",
  "rs_challenge": "False",
  "network": "predefined"
}