Paste: request parsing

Author: itmuckel
Mode: factor
Date: Fri, 19 Jun 2020 21:19:30
Plain Text |
: parse-request ( request-hashtable -- request-message )
  <request-message>
    dup "id" swap at >>id
    dup "method" swap at >>method
    "params" swap at >>params ;

Annotation: listener snippet; probably a more clever way to do this without repeating `of` 3 times

Author: ^alex
Mode: factor
Date: Fri, 19 Jun 2020 23:59:15
Plain Text |
IN: scratchpad TUPLE: request-message id method params ;
IN: scratchpad C: <request-message> request-message
IN: scratchpad "{\"params\": [], \"method\": \"PUT\", \"id\": 10}" json>
IN: scratchpad Command: continue-restart
1: Note:
Added "json.reader" vocabulary to search path

--- Data stack:
H{ { "id" 10 } { "params" ~array~ } { "method" "PUT" } }
IN: scratchpad [ "id" of ] [ "method" of ] [ "params" of ] tri

--- Data stack:
10
"PUT"
{ }
IN: scratchpad <request-message>

--- Data stack:
T{ request-message f 10 "PUT" ~array~ }

Annotation: without repeating `of`:

Author: ^alex
Mode: factor
Date: Sat, 20 Jun 2020 00:04:39
Plain Text |
TUPLE: request-message id method params ;
C: <request-message> request-message

: parse-request ( request-hashtable -- request-message )
    "id" "method" "params" [ [ of ] curry ] tri@ tri ;

New Annotation

Summary:
Author:
Mode:
Body: