An Express-like HTTP router for Bash compatible with CGI 1.1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
953 B

2 years ago
# Exprash
An Express-like HTTP router for Bash compatible with CGI 1.1
I'm aware that the name of this project evokes a feeling of physical disgust. That is by design.
## Usage/Examples
Here is some leaked source code for my brand new Cat website. Do not steal!
```shell
#!/bin/bash
printf '%s\n\n' 'Content-Type: text/html';
2 years ago
source exprash.sh;
2 years ago
declare -A cats;
cats[calico]="Calico";
cats[sphynx]="Sphynx";
cats[ragdoll]="Ragdoll";
cats[scottish_fold]="Scottish Fold";
get '/' && {
printf '<h1>Cats</h1>\n';
printf '<ul>\n';
for key in "${!cats[@]}"; do
printf '<li><a href="cats/%s">%s</a></li>\n' "$key" "${cats[$key]}";
done
printf '</ul>\n';
}
get '/cats/:cat' && {
key=$(param 'cat');
if [[ -v "cats[$key]" ]]; then
printf '<h1>Your Cat: %s</h1>\n' "${cats[$key]}";
else
next;
fi;
}
2 years ago
use && {
2 years ago
printf '<h1>Error: Cannot find that cat</h1>\n';
}
```
## License
[WTFPL](http://www.wtfpl.net/txt/copying/)