Skip to content

Commit

Permalink
Added json-receiver example
Browse files Browse the repository at this point in the history
  • Loading branch information
shirok committed Feb 23, 2018
1 parent f757e04 commit da1767b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/json-receiver.scm
@@ -0,0 +1,26 @@
#!/usr/bin/env gosh

;;
;; Receives json via POST message and returns it in json,
;; as well as writes it out to stdout. Useful to be a receiving
;; end of testing json post feature.
;;
;; Run it in the top source directory of Gauche-makiki.
;;

(add-load-path ".." :relative)
(use makiki)
(use gauche.parseopt)

(define (main args)
(let-args (cdr args) ([port "p|port=i" 8012])
(start-http-server :access-log #t :error-log #t :port port))
0)

(define (handler req app)
(let1 body (request-param-ref req "json-body" :default '())
(display #"==== ~(sys-ctime (current-time))")
(pprint body)
(respond/ok req `(json ,body))))

(define-http-handler #/.*/ (with-post-json handler))

0 comments on commit da1767b

Please sign in to comment.