Network
Creating and Running a Server
Objective: Create a server that responds to GET requests.
- 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":
- This file returns "Hello, World!" in response to the request.
Making HTTP Requests
Objective: Perform a GET request to an external API.
- 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.
- 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":
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
Creates a new server and stores it in a variable of type SERVER.
newVarName: The name of the variable for the server (type: SERVER).
This example creates a new server and stores it in "myServer".
Adds a route to a server that runs a file to handle requests, storing the response in a variable.
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).
This example adds a GET route "/all" to "myServer" that runs "/all.steps".
Runs a server on a specified port to handle requests based on added routes.
port: The port to run the server on (type: VAR).newVarName: The name of the server variable (type: SERVER).
This example runs "myServer" on port 8080 with a "/all" route.
Stops a server running on a specified port.
port: The port of the server to stop (type: VAR).newVarName: The name of the server variable (type: SERVER).
This example runs a server for 5 seconds and then stops it.
Performs an HTTP request and stores the status and response body in new variables.
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).
This example sends a GET request to "http://example.com" and prints the response body.