summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md45
1 files changed, 39 insertions, 6 deletions
diff --git a/README.md b/README.md
index c516e4b..8ba0773 100644
--- a/README.md
+++ b/README.md
@@ -4,20 +4,53 @@ A very goofy http server that runs scripts based of the given URI route
## Config
-All routs and scripts must be layed out in a file called config, or you can specift the path by setting the `CONFIG_PATH` env variable.
+All routes and scripts must be layed out in a file called config, or you can specift the path by setting the `CONFIG_PATH` env variable.
An example config is shown below
```
-/ ./hello_world
-/neo /usr/bin/neofetch
-/joe ./bide
+GET / command.sh
+POST /joe headers.sh
+POST /echo body.sh
```
-As shown above, each route to script is a single line seperated by a single space.
+As shown above, each line is the method route given to run a given script.
## Scripts
-The request body (if it has one) is set to argument 1 of the script. If there was on body provided the argument will be left empty. Anything written to the scripts stdout will be returnd to the http request.
+Anything written to a scripts stdout will be treated as part of the HTTP Response.
+Therefore the first things returned will be treated as headers. To stop reading headers, print a `\n` to stdout to
+tell the HTTP Response that the headers have ended.
+
+All content after the headers will be treated as the response body, and the scripts exit code will be treated as the http response code.
+
+An example script that gives custom headers is shown below:
+```sh
+#!/bin/bash
+
+# print headers that will be returned
+printf "Content-Type: text/plain\n"
+printf "aaaaaaaa: AAAAAAAAAA\n"
+printf "\n"
+
+printf "joe\n"
+
+# return http code 200
+exit 200
+```
+
+Finally if you wish to read the request body given by the user, that is always stored in argument 1. For example to create a echo endpoint:
+```sh
+#!/bin/bash
+
+# even though we have no headers
+# we still need to tell there will be no more headers
+printf "\n"
+
+# the body of any http request made will be stored in argument 1
+printf "$1"
+
+exit 200
+```
## License
This project is licensed under the [WTFPL](https://www.wtfpl.net/)