Skip to content

Instantly share code, notes, and snippets.

@anthonyquizon
Created June 5, 2020 03:50
Show Gist options
  • Save anthonyquizon/2f6a04b1fb16780e711a729ab43dd854 to your computer and use it in GitHub Desktop.
Save anthonyquizon/2f6a04b1fb16780e711a729ab43dd854 to your computer and use it in GitHub Desktop.
Example of using web client in guile
(use-modules (web client)
(web response)
((rnrs) :version (6)))
(define port "8000")
(define body "{\"foo\": \"xyx\"}" )
;; GOTCHAs
;; Body needs to be converted from string to utf8 and back again
;; Need to destructure response with let-values in order to get body string
;; if streaming is set to #t, this will be a port
(let-values ([(res body) (http-request (string-append "http://localhost:" port)
#:method 'POST
#:headers '((Content-Type . "application/json"))
#:streaming? #f
#:decode-body? #t
#:body (string->utf8 body))])
(display (utf8->string body))
(display "\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment