Hi again,
finally I've found it
Sorry, I was in hurry and sent it to wrong place first time :)

The same at pastebin: https://pastebin.com/nQVqbrUz

#
# Mansur Mamkin <mmam...@mail.ru>
# httpjson.l adds support for POST-requests with JSON body
#

(push '*Mimes '(`(chop "json") "application/json; charset=utf-8"))

(de _htJson ()
   (let F (tmp "json.json")
      (out F (echo *ContLen))
      (in F (setq *JSON (readJson T))) ) )

(patch http
'(cond @A ((=0 *ContLen)) @B)
(fill
 '(cond
^ @A
((=0 *ContLen))
((pre? "application/json" *ContentType) (_htJson))
^ @B ) ) )


(patch _htHead
'("content-type:" @A)
'("content-type:"
            (char) # or better (skip)?
            (case (lowc (till "/" T))
               ("multipart"
                  (if (= "/form-data; boundary" (lowc (till "=" T)))
                     (setq
                        *ContentType "multipart/form-data"
                        *MPartLim (append '(- -) (cdr (line)))
                        *MPartEnd (append *MPartLim '(- -)) )
                     (line) ) )
               (T (setq *ContentType (pack @ (line T))) ) ) ) )

#example
#{
(allow "!getjson")

(de getjson ()
   (msg 'JSON= (sym *JSON))
   (let F (tmp "out.json")
      (out F (printJson '(("answerParam" . "ok"))))
      (httpEcho F "application/json; charset=utf-8" 1) ) )

}#

Best regards,
Mansur Mamkin

On Sat, May 18, 2019 at 8:29 PM C K Kashyap <ckkash...@gmail.com> wrote:

On Sat, May 18, 2019 at 8:29 PM C K Kashyap <ckkash...@gmail.com> wrote:

> Hi Alex et al,
>
> I need a sample to handle HTTP post. All I need to do is listen for HTTP
> post request, read the payload in the body and respond. Before you get
> tempted to say a variation of RTFM - let me say that I promise to share an
> interesting demo once I have that :)
>
> Regards,
> Kashyap
>
>

Reply via email to