24.2.1Defining a Handler
We are going to extend the todo application from Chapter 15 with a REST API. We will first build a service that returns a textual list of todo items.
Our REST handler, named ToDoHandler
, should be declared by defining a Seaside class which inherits from WARestfulHandler
. This way we indicate to Seaside that ToDoHandler
is a REST handler. The todo items will be accessed through the same model as the existing todo application: ToDoList default
. This means we do not need to specify additional state in our handler class.
WARestfulHandler subclass: #ToDoHandler
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'ToDo-REST'
With Seaside-REST, we do not subclass from WAComponent
that is reserved to the generation of stateful graphical components, but you should subclass from WARestfulHandler.
Last we need to initialize our hander by defining a class-side initialization method. We register the handler at the entry point todo-api
so that it is reachable at http://localhost:8080/todo-api. Don’t forget to call the method to make sure the handler is properly registered.
ToDoHandler class>>initialize
WAAdmin register: self at: 'todo-api'