Dynamic Web Development with Seaside

24.3.1HTTP Method

Every service method must have a pragma that indicates the HTTP method on which it should be invoked.

If we would like to add a service to create a todo item with a POST request, we could add the following method:

ToDoHandler>>create
<post>

ToDoList default items
add: (ToDoItem new
title: self requestContext request rawBody;
yourself).
^ 'OK'

We use the message rawBody to access the body of the request. The code creates a new todo item and sets its title. It then replies with a simple OK message.

To give our new service a try we could use cURL. With the -d option we define the data to be posted to the service:

$ curl -d "Give REST a try" http://localhost:8080/todo-api
OK

If we list the todo items as implemented in the previous section we should see the newly created entry:

$ curl http://localhost:8080/todo-api
Finish todo app chapter
Annotate first chapter
Discuss cover design
Give REST a try

Similarly Seaside supports the following request methods:

Request Method Method Annotation Description
GET <get> lists or retrieves a resource
PUT <put> replaces or updates a resource
POST <post> creates a resource
DELETE <delete> removes a resource
MOVE <move> moves a resource
COPY <copy> copies a resource

Copyright © 19 March 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.