Created
June 5, 2020 03:50
-
-
Save anthonyquizon/2f6a04b1fb16780e711a729ab43dd854 to your computer and use it in GitHub Desktop.
Example of using web client in guile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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