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, all that is needed is to create a form in a solution and add the following methods to the form:
- ws_read() for the GET operation
- ws_create() for the POST operation
- ws_delete() for the DELETE operation
- ws_update()  for the PUT operation

The RESTRESTful Web Service API is accessible published on the Servoy Application Server through the url: http://domain:port/<serverUrl>/servoy-service/rest_ws/solutionName/formName

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 save any state. 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 

For more information on RESTfull 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]

In each method, the required business logic can be coded. Make sure all methods are stateless, thus do not rely on form and/or global variables, do not alter the solution blueprint using the solution model or change the state of forms as subsequent calls to the API can be handled by different headless clients. 


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.

{note:title=RESTful Web Services & [Servoy Cluster]}Be aware of the ....{note}{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}