downstream-server v0.2.2
Downstream Server
A cross-application server system designed for simple content servers.
Upcoming features
- HTTPS support
- HTTP header read/write access
- Reusable behaviours
Example Server
Create a provider.dsp
file and add the following:
[/] => pass "<h1>Hello World!</h1>"
Then run: down-serve
and visit "localhost"
Basic Syntax
Global Syntax
Comments are denoted by a //
Variables are accessed by an @
, and can be reference as pointers with &
.
Stream declaration
URL handlers are denoted by [...]
, and can contain a valid URL and variables.
[/test/@var/item]
All streams require a behaviour.
Behaviours
Behaviours are declare with an =>
. Behaviours consist of actions, which are separated by ->
.
=> log "This is a test" -> pass "Hello world!"
Config
There are two types of configuration, environment config, and external commands
Environment config
config name value
Here's a full list of configurations, More will be added soon:
root
: The directory to start in for file loading
showErrors
: Controls whether errors are returned
httpPort
: The HTTP port to listen on, defaults to 80
External declerations
Downstream supports calling terminal commands in place of built-in methods.
extern cli_command method_name
Using an external command is identically to a built-in method.
... -> my_command arg1 arg2 -> ...
Method Reference
!
: Denotes a breakpoint, this will halt execution and print out the current context. Execution will resume when return is pressed in the host console.
log
...value : Writes text to the host console.
pass
body : Sets the response body value.
decodeURI
uri : Decodes a given URI. Example: "Hello%20World!"
becomes "Hello World!"
put
&variable : Inserts the response body into a variable pointer.
readFile
filename : Inserts the contents of a file into the response body.
populate
: Allows for the inserting of variables into the response body. Example <h1>@title</h1>
become <h1>Test</h1>
where @title is Test
.
split
delimiter ...pointers : Splits the response body by the delimiter and maps the results to the pointers given.