A Simple HTTP Application
As a pretext to revisit Pharo Syntax
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
A Tiny Book Server
Getting a Book
- Class name starts with an uppercase
new
is a message sent to the class ZnClient
url:
and get
are both sent to the instance of ZnClient
Adding a Book
formAt: 'author' put: 'van Caekenberghe et al'
is equivalent to
formAtput('author' , 'van Caekenberghe et al')
The Full Server
Configuring a Server
| |
delimits local variable definition
:=
assignment
#port
is a symbol (aka unique string)
configure:
is a message sent to the class Teapot
- In
configure:
, :
means that the message is expecting an argument
{ . . }
is an array of three elements
->
creates a key-value pair
Defining The Server Routes
More About Syntax
Processing URIs such as:
http://localhost:8181/books/1
[ :request | books at: (request at: #id) asString ]
is a block
- acts as an anonymous method
:request
is an argument
at:
is a message accepting one argument
Conclusion
- Teapot is a cool package
http://smalltalkhub.com/#!/~zeroflag/Teapot
- A web server in one page
- Based on Zinc a really strong and well designed HTTP client/server
/