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: