Dynamic Web Development with Seaside

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'

Copyright © 21 April 2024 Stéphane Ducasse, Lukas Renggli, C. David Shaffer, Rick Zaccone
This book is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 license.

This book is published using Seaside, Magritte and the Pier book publishing engine.