ZnClient new
url: 'http://localhost:8181/books/1';
get
new
is a message sent to the class ZnClient
url:
and get
are both sent to the instance of ZnClient
ZnClient new
url: 'http://localhost:8181/books/1';
formAt: 'author' put: 'van Caekenberghe et al';
formAt: 'title' put: 'Entreprise Pharo';
post
formAt: 'author' put: 'van Caekenberghe et al'
is equivalent to
formAtput('author' , 'van Caekenberghe et al')
books := Dictionary new.
teapot := Teapot configure: {
#defaultOutput -> #json. #port -> 8181 }.
teapot
GET: '/' -> '<h1>A simple book server</h1>'; output: #html;
GET: '/books' -> books;
GET: '/books/<id:IsInteger>'
-> [ :request | books at: (request at: #id) asString];
POST: '/books/<id>'
-> [ :request | | book |
book := { 'author' -> (request at: #author).
'title' -> (request at: #title) } asDictionary.
books at: (request at: #id) put: book ];
start.
| books teapot |
books := Dictionary new.
teapot := Teapot configure: { #defaultOutput -> #json. #port -> 8181 . #debugMode -> true }.
| |
delimits local variable definition:=
assignment#port
is a symbol (aka unique string)configure:
is a message sent to the class Teapot
configure:
, :
means that the message is expecting an argument{ . . }
is an array of three elements->
creates a key-value pairteapot
GET: '/'
-> '<h1>A simple book server</h1>'; output: #html;
GET: '/books'
-> books;
GET: '/books/<id:IsInteger>'
-> [ :request | books at: (request at: #id) asString];
POST: '/books/<id>'
-> [ :request | | book |
book := { 'author' -> (request at: #author) .
'title' -> (request at: #title) } asDictionary.
books at: (request at: #id) put: book ];
start.
Processing URIs such as:
http://localhost:8181/books/1
teapot
GET: '/books/<id:IsInteger>'
-> [ :request | books at: (request at: #id) asString];
[ :request | books at: (request at: #id) asString ]
is a block :request
is an argumentat:
is a message accepting one argumenthttp://smalltalkhub.com/#!/~zeroflag/Teapot
/