Smalltalk/X WebserverDocumentation of class 'HTTPSimplePluggableJSONRestService': | |
Class: HTTPSimplePluggableJSONRestServiceInheritance:Object | +--HTTPService | +--HTTPRestService | +--HTTPSimplePluggableJSONRestService
Description:A pluggable JSON based Rest services. This answers with a block's return value, which can be configured dynamically. This is especially useful for ad-hoc and mock Rest services (for example, in expecco). Also provides a common 'protocolInfo' entry, which allows querying the supported entries. [start Server with:] HTTPServer startServerOnPort:9876 [configure service entries and start with:] (HTTPSimplePluggableJSONRestService new) entryName:'operation1' getOrPut:'GET' parameterType:#String returnType:#String actionBlock:[:request :arg | 'Hello World']; entryName:'operation2' getOrPut:'GET' parameterType:#Dictionary returnType:#Dictionary actionBlock:[:request :arg | Dictionary withKeys:#('x' 'y' 'z') andValues:#(10 20 'Hello World') ]; entryName:'operation3' getOrPut:'PUT' parameterType:#Integer returnType:#Integer actionBlock:[:request :arg | arg + 1 ]; linkName:'/rest'; registerServiceOn:(HTTPServer runningServerOnPort:9876) [request:] (HTTPServer runningServerOnPort:9876) debugErrors:true. |data| data := HTTPInterface getFile:'localHost:9876/rest/protocolInfo'. data := JSONReader fromJSON:data. Transcript showCR:data |response data| response := HTTPInterface put:'localHost:9876/rest/operation3' with:'123' contentType:'text/json'. data := JSONReader fromJSON:response data. Transcript showCR:data |data| data := HTTPInterface getFile:'localHost:9876/rest/operation1'. data := JSONReader fromJSON:data. Transcript showCR:data [instance variables:] [class variables:] Instance protocol:call entries initialization request handling
Private classes:EntryInfo |
|
ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:25:06 GMT |