unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Gentoo Arch <gentoocore@firemail.cc>
To: guile-user@gnu.org
Subject: Operate upon POST request with Guile webserver
Date: Wed, 17 Aug 2022 14:50:46 +0300	[thread overview]
Message-ID: <828eadbc-c2bf-c4ab-0833-96c55011d36c@firemail.cc> (raw)

Hi,

I'd like to ask for your advice.

I'm trying to figure out how Guile webserver works to develop a simple 
BBS  and I'm kinda stuck with POST request.

My Guile script generates a form on any path and the form sends to 
"/post" path, where I can easily render content sent by the form.

(define (show-page request body)
   (if (equal? (get-path request) ; get-path is my other function to retrieve the path
               '("post"))
       (values '((content-type . (text/plain)))
                body)
       (respond ; literally a respond template from webserver doc
        `((h1 "Oops!")
      (p (@ (id "test")) "The path: " ,(get-path request))
      (form (@ (method "POST") (action "/post"))
            (label (@ (for "test")) "Content: ")
            (input (@ (id "test") (type "text") (name "content")))
            (input (@ (type "submit") (value "Submit"))))))))

But I would like to operate upon the content the form sends like web 
apps usually do: insert it in the database or simply write to file. So 
my question is how I can proceed with something like that:

(define tf (open-file "test-file.txt" "a"))

(define (show-page request body)
   (if (equal? (get-path request)
               '("post"))
       ((values '((content-type . (text/plain)))
               body)
        (display body tf)); I'd like to write/append body to the file, but it does nothing
       (respond
        `((h1 "Oops!")
      (p (@ (id "test")) "The path: " ,(get-path request))
      (form (@ (method "POST") (action "/post"))
            (label (@ (for "test")) "Content: ")
            (input (@ (id "test") (type "text") (name "content")))
            (input (@ (type "submit") (value "Submit"))))))))

If I remove (values), it does write to a file (with a complaint in 
webserver output), but I'd also like to add some kind of redirect from 
"/post" page after the script has written stuff to file and I can't use 
two functions per response.

Could you please advise how I can achieve this functionality?


             reply	other threads:[~2022-08-17 11:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17 11:50 Gentoo Arch [this message]
2022-08-19 11:00 ` Operate upon POST request with Guile webserver Daniel Meißner
2022-08-20 12:03   ` Gentoo Arch
2022-08-21 19:47 ` Ricardo Wurmus
2022-08-21 20:03   ` Gentoo Arch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=828eadbc-c2bf-c4ab-0833-96c55011d36c@firemail.cc \
    --to=gentoocore@firemail.cc \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).