eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'HTTPSimpleJSONRestService':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: HTTPSimpleJSONRestService


Inheritance:

   Object
   |
   +--HTTPService
      |
      +--HTTPRestService
         |
         +--HTTPSimpleJSONRestService

Package:
stx:goodies/webServer
Category:
Net-Communication-Rest
Version:
rev: 1.33 date: 2019/07/10 23:11:21
user: cg
file: HTTPSimpleJSONRestService.st directory: goodies/webServer
module: stx stc-classLibrary: webServer
Author:
cg

Description:


Abstract superclass for JSON based Rest services.
This answers with a method's return value.
Callable methods are automatically detected by their 'RestCallEntry:' annotation.
See concrete subclasses on how call entries are defined (via the annotation).

Also provides a common 'protocolInfo' entry, which allows querying the supported entries.

[start Server with:]
    HTTPServer startServerOnPort:9876


[request:]
    (HTTPServer runningServerOnPort:9876) debugErrors:true.

    |data|
    data := HTTPInterface getFile:'localHost:9876/rest/protocolInfo'.
    data := JSONReader fromJSON:data.
    Transcript showCR:data


[instance variables:]

[class variables:]


Related information:



Instance protocol:

call entries
o  protocolInfo
walk along superclass chain, up to myself

request handling
o  process: aRequest
handles requests of the form:
<baseUrl>/relPath
and searches for a method with
RestCallEntry: 'relPath'
annotation.
Then this is called with the request and the json decoded argument (or nil).
It is the responsibility of the method to determine if it is a GET, PUT or DELETE, by checking the request.
The returned object is then encoded to json and returned.

o  process: aRequest method: typeOfRequest relativePath: relPath argument: callArgument
handles requests of the form:
<baseUrl>/relPath
and searches for a method with
RestCallEntry: 'relPath'
annotation.
Then this is called with the request and the json decoded argument (or nil).
It is the responsibility of the method to determine if it is a GET, PUT or DELETE by checking the request.
The returned object is then encoded to json and returned.

o  reportNotFound: errMsg moreInfo: moreInfo for: aRequest


Private classes:

    RestCallAnnotation

Demonstration:


    (self new)


    linkName:'/rest';


    registerServiceOn:(HTTPServer runningServerOnPort:9876)



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Fri, 16 Apr 2021 12:14:06 GMT