#!env stsh
framework:ObjectiveHTTPD load.
class Task {
   var <bool> done.
   var title.
   -description { "Task: {this:title} done: {this:done}". }
}
taskList ← #( #Task{ #title: 'Clean my room', #done: false }, #Task{ #title: 'Check twitter feed', #done: true } ).
scheme todo {
   var taskList.
   /tasks { 
      |= { 
         this:taskList.
      }
   }
}.
todo := #todo{ #taskList: taskList }.
server := #MPWSchemeHttpServer{ #scheme: todo, #port: 8082 }.
server start.
shell runInteractiveLoop.
After loading the HTTP framework, we define a
Task and a list of two example tasks.  Then we define 
a scheme with a single path, just /tasks, which returns said tasks list.  We then instantiate the 
scheme and serve it via HTTP on port 8082. Since this is a shell script and starting the server does not block,
we finally start up the REPL.Details such as coding the tasks as JSON, accessing a single task and modifying tasks are left as exercises for the reader.

No comments:
Post a Comment