Cog webserver end-to-end
Document Type: Tutorial
We used some pieces of a webserver cog on the last page just to exemplify how JSON works. As a reminder, this was the summary:
For an example of providing a JSON response from a cog to a web client, we'll pull some lines from
sire/demo_runcog_site.sire
, an example app that allows a web client to start and stop toy timer cogs as well as check the current status of any cogs in the app.
We're going to explain this entire file now, because it has everything you need to build a useful full-stack web app.
Coming soon: This page will thoroughly cover every line of the cog under examination.
Until this page is finished, we'll leave a few terse hints here for the intrepid learner to get started. It's a great final challenge.
Define the shape of our kernel and threads
Set up a fileserver binding
Set up a JSON request handler binding
Start a cog with with the kernel we defined and some threads for the various HTTP handlers
```sire > Ref KernelState > Cog Void = (runHttpServer vSt return) : ??(rhs_heard req) < syscall HTTP_HEAR : _ < handleReq vSt req | runHttpServer vSt return
Cog () = (launchKernel return) : servThread < fork (syscall (**HTTP_SERV emptyFileServer)) : vSt < newRef (PIN | newState servThread) : httpThread1 < fork (runHttpServer vSt) | return ()
main=(runCog launchKernel)
Last updated