[racket] Simple json web response
This is super close to what you want for response/json:
(define (response/jsonp callback o)
(response/output
(λ (op)
(fprintf op "~a(" callback)
(write-json o op)
(fprintf op ");"))
#:mime-type #"application/javascript"))
from
https://github.com/plt/racket/blob/master/pkgs/plt-services/meta/pkg-index/official/jsonp.rkt#L6
If you aren't doing JSONP, just remove the callback stuff and just do
write-json.
Jay
On Tue, Jul 29, 2014 at 1:53 PM, Andrew Dudash <drewdudash at gmail.com> wrote:
> When you say hangs do you mean it freezes? When I run the same code from
> DrRacket, it runs fine. (Sometimes there's a small delay.)
>
> When I view the source of the webpage I get some HTML, so I don't think you
> want to use' response/xexpr' for JSON.
>
>
>
> On Tue, Jul 29, 2014 at 1:28 PM, Eric Gustavson <gustavson.eric at gmail.com>
> wrote:
>>
>> I'm new to racket -- so don't assume I know what I am doing. I tried
>> running this code, and the web server just hangs. I am just trying to
>> get a racket server to return a static json file. Any tips on how to
>> get started would be appreciated.
>>
>> #lang web-server/insta
>>
>> (define (start request)
>> (response/xexpr #:mime-type #"application/json"
>> "{1: 11}"))
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
--
Jay McCarthy
http://jeapostrophe.github.io
"Wherefore, be not weary in well-doing,
for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
- D&C 64:33