Top Banner
Simple Rest Server S. Ducasse http://www.pharo.org
4
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Pharo Hands-On: 04 teapot server

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

Page 2: Pharo Hands-On: 04 teapot server

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

Page 3: Pharo Hands-On: 04 teapot server

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.

Page 4: Pharo Hands-On: 04 teapot server

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