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

Pharo Hands-On: 04 teapot server

  • Upload
    pharo

  • View
    89

  • Download
    0

Embed Size (px)

Citation preview

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