Download and run

Just download a pre-compiled version for your OS.

Run the other examples with curl or Invoke-WebRequest.

$ curl http://localhost:3000/date
Sun Feb 25 11:42:13 CET 2024

$ curl http://localhost:3000/hello-world
Hello World 

$ curl http://localhost:3000/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

Finally, point a browser to the URL http://localhost:3000/button. You will get a button called “Date”. Click on it. After the request has been executed, inside the green confirmation box, click on “Click to inspect” to see how HTTPE has executed a script and send back the output.

A button created from the rules.

A button created from the rules.

Understand the rules

Let’s look at the rule file.

1
2
3
4
5
6
7
8
9
---
## Rules for the HTTP application server
rules:
  - name: Hello World
    on:
      path: /hello
    run.script: |
        echo "Hello {{ .Input.Params.Name }}.
        Have a lovely $(date +%A)! šŸ˜Ž"        
  • All rules must be child items of the rules object. (Line 3)
  • Rules must be defined as a list, hence each rule must start with a dash. (Line 4)
  • A rule must have a name for identification. (Line 4)
  • The on object defines the request matcher. In the shown example the rule takes action if the request goes to the hellopath. Because the method is not defined, this rules takes action on all request methods. (Lines 5-6)
  • With the run.script object (Line 7) you define an action to execute if the on definition matches the request. The script specified will be executed by the default shell. Stdout is returned as http response. (Lines 8-10)
  • {{ .Input.Params.Name }} is a template macro. HTTPE will replace it by the URL parameter Name before execution. (Line 9)