Accessing and exploring HTTP requests emitted by a client is an important task during the development of a REST web service. The request gives access to information about the client (IP address, HTTP agent, ...).
To access the request we can add the expression
self requestContext request inspect anywhere into Seaside code. This works inside a
WAComponent as well as inside a
When the method is executed, you get an inspector on the current request as shown in Figure 158.
The following example uses the expression
headers at: 'content-type' that returns the
Content-Type present in the inspected HTTP client request.
self requestContext request inspect.
^ String streamContents: [ :stream |
In the case of the transmission of a form (corresponding to the application/x-www-form-urlencoded MIME type), we can access the submitted fields using the message
For example we could implement a delete operation for our todo items as follows:
| item |
item := ToDoList default items
detect: [ :each | each title = aString ]
ifNone: [ nil ].
self requestContext respond: [ :response |
ifTrue: [ response status: WARequest statusNotFound ]
ToDoList default remove: item.
response status: WARequest statusOk ] ]
The different status codes are implemented on the class side of WARequest. They are grouped in five main families with numbers between 100 and 500. The most common one is status code
WARequest statusOk (200) and
WARequest statusNotFound (404).