needs net/http



"2e46ca1e-bbf6-4864-94fc-80bcb40885e6" var, uid

"http://xxxxxxxx.yyyyy.io/api%s" var, url



\ This does the API call and shows the results:

: docall

"Testing " . . cr

net:post/get if

json>

else

"Failed API"

then

. cr

drop ;



\ Add the 'url' key as appropriate:

: +url \ map uid? -- map

null? if drop "" then

"/" swap s:+ url @ s:strfmt

"url" swap m:! ;



\ Create new post/get data:

: postdata \ x -- map

{ "headers" : { "Content-Type" : "application/json", } }

swap +url ;



\ init API

: init

null postdata

"data" {} "uuid" uid @ m:! m:!

"POST" "init" docall ;



\ info API

: info

uid @ postdata

"GET" "info" docall ;



\ update API

: update

uid @ postdata

"data" { "status" : {"temp":31, "uptime":2000, "android":22, "apk":1 } } m:!

"PUT" "update" docall ;



"Testing APIs: " . cr

init update info

"Done testing" . cr



bye



Testing APIs:

Testing init

{"errors":["Uuid has already been taken"]}

Testing update

{}

Testing info

{"update_period":60,"status":{"apk":1,"android":22,"uptime":2000,"temp":31},"short-id":"FC20E8","uuid":"2e46ca1e-bbf6-4864-94fc-80bcb40885e6"}



A client of mine is establishing some APIs for me to call, and it's inconvenient to try to test them from within a device. So here's a simple 8th "mockup" to test the APIs. Obviously, the URL is fictitious:This outputs: