Meet Virtel Maple 3.4.x! New UI, Custom colors, PQCrypto and Fixes.

Download

Network

Creating and Running a Server

Objective: Create a server that responds to GET requests.

Steps:
  • Create the server:
    srv new "8080" server;
    • "8080" is the server port.
    • "server" is the variable name to store the server object.
  • Add a route:
    srv add "get" "/" "/index.steps" response server;
    • "get" is the HTTP request method.
    • "/" is the route path.
    • "/index.steps" is the file to handle the request.
    • "response" is the variable to store the result.
    • "server" is the variable with the server object.
  • Run the server:
    srv run server;

File "/index.steps":

var set "Hello, World!" response;
  • This file returns "Hello, World!" in response to the request.

Making HTTP Requests

Objective: Perform a GET request to an external API.

Steps:
  • Define request parameters:
    var set "get" method; var set "https://api.example.com/data" url; var set "" body;
    • "method" is the request method.
    • "url" is the URL address.
    • "body" is the request body.
  • Execute the request:
    clt req method url body status bodyResult;
    • "status" is the variable to store the response status.
    • "bodyResult" is the variable to store the response body.
  • Display the result:
    str add "Status: " status status; str add ", Body: " bodyResult bodyResult; str add status bodyResult message; csl write message;

Practical Example

Objective: Create a server that handles GET requests and returns a greeting.

Steps:
  • Create the server:
    srv new "8080" server;
  • Add a route:
    srv add "get" "/hello" "/hello.steps" response server;
  • Run the server:
    srv run server;

File "/hello.steps":

var set "Hello, User!" response;

Result:

  • Open a browser and navigate to http://localhost:8080/hello.
  • You will see the message "Hello, User!".

Tips

  • Test your servers and requests regularly to avoid errors.
  • Choose ports and routes carefully to avoid conflicts.
  • Comment your code for better understanding.

Conclusion

Virtel Steps offers simple and convenient tools for networking. Use the commands srv new, srv add, srv run to create servers, and clt req to make HTTP requests. This allows you to quickly develop network applications.

Commands

srv new

Creates a new server and stores it in a variable of type SERVER.

srv new (newVarName)
  • newVarName: The name of the variable for the server (type: SERVER).
srv new myServer;

This example creates a new server and stores it in "myServer".

srv add

Adds a route to a server that runs a file to handle requests, storing the response in a variable.

srv add (method) (route) (file) (resVarName) (newVarName)
  • method: The HTTP method ("get", "post", "delete") (type: VAR).
  • route: The route path (e.g., "/all") (type: VAR).
  • file: The file to handle the request (type: VAR).
  • resVarName: The variable name for the response in the handling flow (type: VAR).
  • newVarName: The name of the server variable (type: SERVER).
srv new myServer; srv add "get" "/all" "/all.steps" allRes myServer;

This example adds a GET route "/all" to "myServer" that runs "/all.steps".

srv run

Runs a server on a specified port to handle requests based on added routes.

srv run (port) (newVarName)
  • port: The port to run the server on (type: VAR).
  • newVarName: The name of the server variable (type: SERVER).
srv new myServer; srv add "get" "/all" "/all.steps" allRes myServer; srv run "8080" myServer;

This example runs "myServer" on port 8080 with a "/all" route.

srv stop

Stops a server running on a specified port.

srv stop (port) (newVarName)
  • port: The port of the server to stop (type: VAR).
  • newVarName: The name of the server variable (type: SERVER).
srv new myServer; srv run "8080" myServer; run pause "5000"; srv stop "8080" myServer;

This example runs a server for 5 seconds and then stops it.

clt req

Performs an HTTP request and stores the status and response body in new variables.

clt req (method) (url) (body) /type/ (newVarNameStatus) (newVarNameBody)
  • method: The HTTP method ("get", "post", "delete") (type: VAR).
  • url: The URL for the request (type: VAR).
  • body: The request body (empty string for GET/DELETE) (type: VAR).
  • type: Optional, only for "json" body value "json"
  • newVarNameStatus: The variable for the response status (type: VAR).
  • newVarNameBody: The variable for the response body (type: VAR).
clt req "get" "http://example.com" "" status body; csl write body;

This example sends a GET request to "http://example.com" and prints the response body.