]> gitweb.factorcode.org Git - factor.git/commitdiff
json: add json.http and some helper words for http requests
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 18 Apr 2023 00:12:30 +0000 (19:12 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 18 Apr 2023 14:02:18 +0000 (09:02 -0500)
basis/json/http/authors.txt [new file with mode: 0644]
basis/json/http/http.factor [new file with mode: 0644]
basis/json/json.factor

diff --git a/basis/json/http/authors.txt b/basis/json/http/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/json/http/http.factor b/basis/json/http/http.factor
new file mode 100644 (file)
index 0000000..a28406d
--- /dev/null
@@ -0,0 +1,16 @@
+! Copyright (C) 2023 Doug Coleman.
+! See https://factorcode.org/license.txt for BSD license.
+USING: http.client json kernel ;
+IN: json.http
+
+: json-get* ( endpoint -- res json ) http-get* ?json> ;
+: json-post* ( post-data endpoint -- res json ) http-post* ?json> ;
+: json-put* ( post-data endpoint -- res json ) http-put* ?json> ;
+: json-patch* ( patch-data endpoint -- res json ) http-patch* ?json> ;
+: json-delete* ( endpoint -- res json ) http-delete* ?json> ;
+
+: json-get ( endpoint -- json ) http-get nip ?json> ;
+: json-post ( post-data endpoint -- json ) http-post nip ?json> ;
+: json-put ( post-data endpoint -- json ) http-put nip ?json> ;
+: json-patch ( patch-data endpoint -- json ) http-patch nip ?json> ;
+: json-delete ( endpoint -- json ) http-delete nip ?json> ;
index 13cced3e8dca08b8f90250a1030f423b29071e8d..0a73dad4668a30d4fa0707f94a935a57b87f2708 100644 (file)
@@ -314,3 +314,6 @@ M: hashtable stream-json-print json-print-assoc ;
 
 M: word stream-json-print
     [ name>> ] dip stream-json-print ;
+
+: ?>json ( obj -- json ) dup string? [ >json ] unless ;
+: ?json> ( obj -- json/f ) f like [ json> ] ?call ;