-
Notifications
You must be signed in to change notification settings - Fork 0
Integration
To integrate the server functionality with a cognitive task, the task must implement functionality that allows it to exchange data with the server.
- Standardizing the format and structure of data to be sent to the server from the task. This ensures that the R script can validate any received data.
- Standardizing the format and structure of data to be received by the task from the server. This allows the task to utilize the data to construct dynamic behavior as defined by the server output and minimize the likelihood of issues arising during task delivery.
⚠️ Sending request and awaiting responses in JavaScript is an asynchronous operation and may require refactoring of source code to ensure the cognitive task is halted while awaiting a response from the server.
JavaScript itself provides functionality to send requests asynchronously without the need for additional libraries.
const response = fetch("http://localhost/task", {
headers: {
"Content-Type": "application/json",
},
// Pass data in the request body
body: JSON.stringify(data),
})
.then((response) => {
// Parse and return the response from the server
return response.json();
});You can read more about the Fetch API here.
The Axios library packages this functionality into a straighforward set of functions and parameters, and is a good alternative to the default JavaScript implementation.
// Example using Axios
const response = axios.get("http://localhost/task", {
params: data,
})
.then((response) => {
// Parse and return the response from the server
return response.json();
});You can read more about the Axios library here.
Feedback? Questions? Please reach out or create an issue under this repository.
Lab Website: Brain Development and Disorders Lab
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
