#! /home/frew/tmp/factor/factor USING: http.client json.reader io.encodings.string io.encodings.utf8 accessors furnace.actions html.forms http http.server kernel assocs sequences http.server.dispatchers http.server.responses namespaces urls xml.syntax xml.writer ; IN: friendly.tea : _data ( t -- d ) "data" swap at ; : _unpack ( url -- d ) http-get swap drop utf8 decode json> _data ; : current-time ( -- t ) "http://localhost:5000/current_tea" _unpack ; : all-times ( -- t ) "http://localhost:5000" _unpack ; : nth-time ( n -- t ) all-times nth ; : rand ( -- t ) "http://localhost:5000/rand" _unpack ; : name ( t -- n ) "name" swap at ; : steep-time ( t -- n ) "steep_time" swap at ; : preparation-time ( t -- n ) "preparation_time" swap at ; : available-time ( t -- n ) "available_time" swap at ; : page ( text -- xml ) <XML <html> <head> <title> "tea" </title> </head> <body> <p> <-> </p> </body> </html> XML> xml>string ; TUPLE: hello < dispatcher ; : <hello-action> ( -- action ) <page-action> [ current-time name page "text/html" <content> ] >>display ; : <hello> ( -- dispatcher ) hello new-dispatcher <hello-action> "" add-responder ; : run-hello ( -- ) <hello> main-responder set-global 8080 httpd ; MAIN: run-hello
Done