Add CGI example for client inputs in spartan wiki page

This commit is contained in:
hedy 2022-03-30 15:49:46 +08:00
parent cb3ea33d9e
commit be18ce058d
Signed by: hedy
GPG Key ID: B51B5A8D1B176372
1 changed files with 55 additions and 0 deletions

View File

@ -86,3 +86,58 @@ alternatively you could send input directly in gelim:
(note: `-I` is so gelim quits immediately after displaying output, `-i` is for
sending the input)
### greeter example
what makes spartan distinct from gemini is the ability to send in data together
with any spartan request. for example, try doing:
gelim spartan://mozz.us/echo -Ii 'hello spartan'
this sends the data "hello spartan" along to the request, and the `/echo` path
of `mozz.us` server would then echo back whatever you've sent it, in this case,
"hello spartan".
you can make your own echo CGI script too! first, create a new executable file
for your script:
mkdir ~/public_spartan
cd ~/public_spartan
touch echo.sh
chmod o+x echo.sh
then open the script with the editor of your choice and add the following:
#!/usr/bin/env sh
printf "2 application/octet-stream\r\n"
cat /dev/stdin
save the script, then try it out!
gelim spartan://username.tilde.cafe/echo.sh -Ii 'this is my input'
it's that easy :) remember to replace `username` with your username and
`echo.sh` to the path of your script
next, let's try building a simple greeter program.
create a new file that will hold your script, make it executable, then put the
following in:
#!/usr/bin/env sh
printf "2 text/plain\r\n"
name=$(cat /dev/stdin)
echo "Hello, ${name:-World}!"
simple, right? let's try it out!
gelim spartan//username.tilde.cafe/greet.sh -Ii 'yourname'
replace `username` with your username, `greet.sh` with the path to your script,
and `yourname` to anything you like.
feel free to drop by `#spartan` or `#cafe` on [tilde.chat irc](irc.html) if you have
questions.