Include this Package with
[i] This package includes 2 functions and 3 Classes.
The first of the tree Classes, is the WebRequest Class.
It's Constructor only takes one Argument, that being a string setting the Request type. Valid Types are: "POST" and "GET". (There might be more in the future).
Creating a WebRequest, could look like this:
var req <- make WebRequest("POST");
If you are making a POST Request, you can now add your Form fields with the AddField function:
req->AddField("field0", "some data");
req -> AddField("creativeFieldName", "more data");
You are also able to add Headers to your Request:req->AddHeader("name", "value");
To now send the Request, just call SendRequest. If you are making a GET Request, you can put your data into the URL now.
When run, this function will return a...
var response <- req -> SendRequest("https://bytespace.tk/");
HttpResponse has 4 Fieldsresponse -> Headers //the response headers as stringArr
response -> StatusCode //the http status code of the response
response -> wasSuccessful //a bool saying if the Request was successful or not
response -> Content //the Content sent back from the server as a string
File Up- and Downloading over http
The web package allows you to Upload and Download files over http (and https)
File Uploading could look like this:web::UploadFile("someURL", "/some/path/to/a/file");
File Downloading could look like this:web::DownloadFile("a.url.to.a.file", "/a/location/to/save/it/to");
You can create a Websocket Client by just using its Constructor and passing in a URL.var wsclient <- make WebSocketClient('ws://some.domain/');
To open the connection just call the Open() function:wsclient->Open();
To send a message over the Client just use its Send() function:wsclient->Send("message");
If you want to Receive data from the Client just call its Receive() function. (NOTE: this will pause the Thread until a message is received.)var answer <- wsclient->Receive();
To close the Client you can call its Cancel() function at any time.wsclient->Cancel();