Do you remember last week when I told you I am going to send fake data so that I can work on the technique of getting the code and schematic to communicate first then go back to the problem of matching the variable names with the right variable type? Well, I was able to send data in JSON form from C++ code to the JavaScript. This is possible to be done using HTTP requests. Let me explain to you a bit about that. HTTP stands for Hypertext Transfer Protocol (HTTP) which is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and server. A web browser may be the client, and an application on a computer that hosts a website may be the server. Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.

HTTP Methods

  • GET
  • POST
  • PUT
  • DELETE


The GET Method

GET is used to request data from a specified resource.
GET is one of the most common HTTP methods.

Note that the query string (name/value pairs) is sent in the URL of a GET request:
/test/demo_form.php?name1=value1&name2=value2


The POST Method

POST is one of the most common HTTP methods.
The data sent to the server with POST is stored in the request body of the HTTP request:
POST /test/demo_form.php HTTP/1.1
Host: host.com
name1=value1&name2=value2


The PUT Method

PUT is used to send data to a server to create/update a resource.
The difference between POST and PUT is that PUT requests are idempotent. That is, calling the same PUT request multiple times will always produce the same result. In contrast, calling a POST request repeatedly have side effects of creating the same resource multiple times.


The DELETE Method

The DELETE method deletes the specified resource.

I have used PUT request to send data. The way I did it is by using jQuery. jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting.
This is an example of how to send PUT request using jQuery:
$.ajax({
url: ‘script.php?info=15’,
type: ‘PUT’,
success: function(data) {
//…

}
});

the first parameter represents the URL request. The second one is the type of the request. The third is the callback of the function that runs if information were received successfully, and s“data” variable represents the received data.
After I sent a PUT request, I was trying to trigger the simulation on the schematic side. However, I had a lot of difficulties to figure out how it works and at which part I can add my code for it to be efficient. When I asked for Dr Shawn help, he told me that I should first follow the code and know the flow of codes that are running, then, it will be easier for me to do my task. Hopefully, I was able to do that. Next week, I will keep trying to trigger the schematic using the data I have sent.


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.