Child pages
  • RESTful Web Services

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: sub-section:description edited
Wiki Markup
{hidden}
DO NOT EDIT THE CONTENT OF THIS PAGE DIRECTLY, UNLESS YOU KNOW WHAT YOU'RE DOING.
		THE STRUCTURE OF THE CONTENT IS VITAL IN BEING ABLE TO EXTRACT CHANGES FROM THE PAGE AND MERGE THEM BACK INTO SERVOY SOURCE{hidden}
{sub-section:description|text=}Using the RESTful Web Service plugin business logic can be exposed as a RESTful Web Service. The RESTful Web Service plugin does not contain any client side functions or properties, it is a 100% server side operating plugin. 

To create a RESTful Web Service, create a form in a solution and add one or more of the following methods to the form:
- ws_read():Object to *retrieve data*
By performing an HTTP GET on the url <serverUrl>/servoy-service/rest_ws/solutionName/formName, the ws_read() method will be invoked. Arguments can be specified in the url, like <serverUrl>/servoy-service/rest_ws/solutionName/formName/value1/value2. The arguments will be applied to the invokation of ws_read().
The method can return a JavaScript object. The object will be serialized and placed in the body of the HTTP Response. If the return value of the method is null, the API will generate a NOT_FOUND response (HTTP 404)
- ws_create():Object to *add data*
By performing an HTTP POST on the url <serverUrl>/servoy-service/rest_ws/solutionName/formName, the ws_create() method will be invoked. Data has to be supplied in the body of the HTTP request.
The method can return a JavaScript object. The object will be serialized and placed in the body of the HTTP Response.
- ws_delete():Boolean to *remove data*
By performing an HTTP DELETE on the url <serverUrl>/servoy-service/rest_ws/solutionName/formName, the ws_delete() method will be invoked. Arguments can be specified in the url, like <serverUrl>/servoy-service/rest_ws/solutionName/formName/value1/value2. The arguments will be applied to the invocation of ws_delete().
The method has to return a Boolean value: 
-- true: to indicate successful deletion. This result will map to an HTTP 200 response
-- false: to indicate delete failure. This response will map to an HTTP 404 response
- ws_update():Boolean to *update data* 
By performing an HTTP PUT on the url <serverUrl>/servoy-service/rest_ws/solutionName/formName, the ws_delete() method will be invoked. Data has to be supplied in the body of the HTTP request.
The method has to return a Boolean value: 
-- true: to indicate successful update. This result will map to an HTTP 200 response
-- false: to indicate update failure. This response will map to an HTTP 404 response

In case the matching method for the specific HTTP operation (GET, POST, DELETE or PUT) does not exists on the form, the API will automatically generate a INTERNAL_SERVER_ERROR response (HTTP 500).

h4.Content-Types
For the POST and PUT operation (resp. ws_create() and ws_update() methods), data has to be supplied in the body of the HTTP Request. The supported Content-Types are JSON (application/json) and XML (application/xml). When no or another content type than JSON or XML is specified, an UNSUPPORTED_MEDIA_TYPE response will be generated (HTTP 415)

The supplied value in the body of the HTTP request will be applied as argument to the invocation of the method. If the content in the body of the HTTP Request is missing, a NO_CONTENT response will be generates (HTTP 204).

h4.Stateless
RESTful Web Services are to be stateless. As subsequent requests to the RESTful Web Service API might be handled by different headless clients in the pool of clients configured for the plugin, do not use any state in between calls to the API. This means at least the following:
- Do not use global or form variables
- Do not use the solution model API
- Do not alter the state of the a form's UI
- Do save or rollback any unsaved changes

h4.ForPool moreof informationClients
onTo RESTfulservice Webthe Services, see:
[http://en.wikipedia.org/wiki/Representational_State_Transfer]
[http://www.infoq.com/articles/rest-introduction]
[http://www.ibm.com/developerworks/webservices/library/ws-restful/]
[http://home.ccil.org/~cowan/restws.pdf]

h4.Samples
A sample solution is included in the Servoy distribution (servoy_sample_rest_ws.servoy), detailing how to retrieve data from the http request and to return a response.

h4.Authentication
The RESTful Web service plugin currently does not support authentication.

h4.Servoy Cluster
The RESTful Web service plugin uses a pool of headless clients to service the requests. When operated within a Servoy Cluster, note that poolsize is set per Servoy Application Server.requests to the RESTful Web service API, the plugin creates a pool of (headless) clients. The maximum number of clients allowed can be set using the "rest_ws_plugin_client_pool_size" property of the plugin (default value = 5).

When there are more concurrent requests than the number of clients in the pool, by default the requests will wait until a client becomes available in the pool. This behavior can be altered by setting the "rest_ws_plugin_client_pool_exhausted_action" property of the plugin. The following values are supported for this property:
- block (default): requests will wait untill a client becomes available
- fail: the request will fail. The APi will generate a SERVICE_UNAVAILABLE response (HTTP 503)
- grow: allows the pool to temporarily grow, by starting additional clients. These will be automatically removed when not required anymore.

{note:title=Servoy Cluster}The RESTful Web service plugin uses a pool of headless clients to service the requests. When operated within a Servoy Cluster, note that poolsize is set per Servoy Application Server.{note}

h4.For more information on RESTful Web Services, see:
[http://en.wikipedia.org/wiki/Representational_State_Transfer]
[http://www.infoq.com/articles/rest-introduction]
[http://www.ibm.com/developerworks/webservices/library/ws-restful/]
[http://home.ccil.org/~cowan/restws.pdf]

h4.Samples
A sample solution is included in the Servoy distribution (servoy_sample_rest_ws.servoy), detailing how to retrieve data from the http request and to return a response.

h4.Authentication
The RESTful Web service plugin currently does not support authentication.

h{sub-section}\\{table:class=servoy sSummery}{colgroup}{column:width=80px}{column}{column}{column}{colgroup}{tr:style=height: 30px;}{th:colspan=2}Server Property Summary{th}{tr}{tbody}{tr}{td}{td}{td}[#rest_ws_plugin_client_pool_exhausted_action]
{td}{tr}{tbody}{tbody}{tr}{td}{td}{td}[#rest_ws_plugin_client_pool_size]
{td}{tr}{tbody}{table}\\{table:class=servoy sDetail}{colgroup}{column:width=100%}{column}{colgroup}{tr:style=height: 30px;}{th:colspan=1}Server Property Details{th}{tr}{tbody:id=420C89DC-38E1-4B81-8126-9F53F84B74E5}{tr:id=name}{td}h6.rest_ws_plugin_client_pool_exhausted_action{td}{tr}{tr:id=des}{td}{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_des|text=|trigger=button}{sub-section}{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_des|trigger=none|class=sIndent}Action when no more clients are availiable (block/fail/grow), default = block{sub-section}{td}{tr}{builder-show:permission=edit}{tr:id=prs}{td}*Parameters*\\{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_prs|text=|trigger=button}{sub-section}{div:class=sIndent}{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_prs|trigger=none}{sub-section}{div}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=ret}{td}*Returns*\\{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_ret|text=|trigger=button}{sub-section}{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_ret|trigger=none|class=sIndent}{sub-section}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=see}{td}*Also see*\\{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_see|text=|trigger=button}{sub-section}{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_see|class=sIndent|trigger=none}{sub-section}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=link}{td}*External links*\\{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_see|text=|trigger=button}{sub-section}{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_link|class=sIndent|trigger=none}{sub-section}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=sam}{td}*Sample*\\{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_sam|text=|trigger=button}{sub-section}{sub-section:420C89DC-38E1-4B81-8126-9F53F84B74E5_sam|class=sIndent|trigger=none}{sub-section}{td}{tr}{builder-show}{tr:class=lastDetailRow}{td}{td}{tr}{tbody}{tbody:id=4059D6A1-372F-4C41-BEA9-3870E51A198A}{tr:id=name}{td}h6.rest_ws_plugin_client_pool_size{td}{tr}{tr:id=des}{td}{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_des|text=|trigger=button}{sub-section}{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_des|trigger=none|class=sIndent}Max number of clients used (this defines the number of concurrent requests and licences used), default = 5{sub-section}{td}{tr}{builder-show:permission=edit}{tr:id=prs}{td}*Parameters*\\{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_prs|text=|trigger=button}{sub-section}{div:class=sIndent}{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_prs|trigger=none}{sub-section}{div}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=ret}{td}*Returns*\\{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_ret|text=|trigger=button}{sub-section}{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_ret|trigger=none|class=sIndent}{sub-section}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=see}{td}*Also see*\\{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_see|text=|trigger=button}{sub-section}{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_see|class=sIndent|trigger=none}{sub-section}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=link}{td}*External links*\\{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_see|text=|trigger=button}{sub-section}{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_link|class=sIndent|trigger=none}{sub-section}{td}{tr}{builder-show}{builder-show:permission=edit}{tr:id=sam}{td}*Sample*\\{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_sam|text=|trigger=button}{sub-section}{sub-section:4059D6A1-372F-4C41-BEA9-3870E51A198A_sam|class=sIndent|trigger=none}{sub-section}{td}{tr}{builder-show}{tr:class=lastDetailRow}{td}{td}{tr}{tbody}{table}