Skip to content

Instantly share code, notes, and snippets.

@jessealama
Last active October 29, 2019 05:38
Show Gist options
  • Save jessealama/e414903ea119e316a8419490a8418033 to your computer and use it in GitHub Desktop.
Save jessealama/e414903ea119e316a8419490a8418033 to your computer and use it in GitHub Desktop.
#lang racket
(require http) ;; not installed by default
;; do raco pkg install http
(define (http-request uri
#:redirects [redirects 10]
#:http-version [http-version "1.1"]
#:method [method "GET"]
#:data [data #""]
#:data-length [data-length #f]
#:heads [heads empty]
#:entity-reader [entity-reader read-entity/bytes])
(if (and (bytes? data)
(bytes=? data #"")
(eq? data-length #f))
(call/input-request http-version
method
uri
heads
entity-reader
#:redirects redirects)
(call/output-request http-version
method
uri
data
data-length
heads
entity-reader
#:redirects redirects)))
@zenspider
Copy link

I was just looking around for such a thing and I went with what I found in stdlib... Here's what I wound up with:

(define (post uri payload)
  (string->jsexpr
   (port->string (post-pure-port (string->url uri)
                                 (jsexpr->bytes payload)))))

(define (get uri)
  (string->jsexpr
   (port->string (get-pure-port (string->url uri)))))

P.S. I think you want not on line 15?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment