pharo hands-on: 04 teapot server

4
Simple Rest Server S. Ducasse http://www.pharo.org

Upload: pharo

Post on 18-Jul-2015

87 views

Category:

Technology


0 download

TRANSCRIPT

Simple Rest ServerS. Ducasse http://www.pharo.org

| books teapot | books := Dictionary new. teapot := Teapot configure: { #defaultOutput -> #json. #port -> 8080. #debugMode -> true }.

teapot GET: '/books' -> books; ! PUT: '/books/<id>' -> [ :request | | book | book := {'author' -> (request at: #author). 'title' -> (request at: #title)} asDictionary. books at: (request at: #id) put: book ]; ! DELETE: '/books/<id>' -> [:request | books removeKey: (request at: #id)]; ! exception: KeyNotFound -> (TeaResponse notFound body: 'No such book'); ! start.

ZnClient new url: 'http://localhost:8080/books/1'; formAt: 'author' put: 'SquareBracketAssociates'; formAt: 'title' put: ‘Enterprise Pharo'; put