[racket] HTTP POST: curl vs racket net library

From: pior neer (pior.neer at gmail.com)
Date: Mon Nov 3 12:31:37 EST 2014

Here is an example (which worked once) I am trying to replicate in Racket.

curl https://api.stripe.com/v1/customers \
   -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
   -d "description=Customer for test at example.com" \
   -d card=tok_14unJi2eZvKYlo2C804uRph5

Here is my Racket code that does a "similar" thing.

#lang racket

(require net/http-client)
(require net/url)
(require net/uri-codec)
(require net/base64)
(require json)

(define (authcode key)
  (base64-encode (string->bytes/utf-8 key)))

(define (make-customer #:email email #:token token)

  (define-values (status-code header inport)
    (http-sendrecv
     "api.stripe.com"
     "/v1/customers"
     #:ssl? #t
     #:method "POST"
     #:data (alist->form-urlencoded
             (list (cons 'card "token")))
     #:headers (list (format "Authorization: Basic ~a"
                             (authcode
"sk_test_BQokikJOvBiI2HlWgH4olfQ2:")))))
  (read-json inport))

(make-customer #:email "jondo at example.com"
               #:token "tok_14unJi2eZvKYlo2C804uRph5" )

The above results in

'#hasheq((error
          .
          #hasheq((param . "\r\ncard")
                  (message
                   .
                   "Received unknown parameter: \r\ncard")
                  (type . "invalid_request_error"))))

Questions:

1) Why does the server parses \r\nkey instead of just key when using Racket?

2) Is there a less verbose way to express the same thing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141103/b3ee77a0/attachment.html>

Posted on the users mailing list.