Writing a Hello World Service !!

JavaScript

The Mashup Server supports the quick and easy creation of Web services written in JavaScript.  Just as a Web server such as Apache or IIS publishes HTML and other Web content from a local directory to the Web, the Mashup Server takes JavaScript files, placed in a local directory, and exposes the functions as Web Service operations.

The simplest way to deploy a new Web service is simply to write some JavaScript and place it in the 'scripts' directory of the Mashup Server.  Follow these simple steps:

Step 1:

In Notepad or your favorite IDE, type the following text:

function hello() {
    return <response>Hello World</response>;
}


Step 2:

Save this file as 'helloworld.js' in the directory 'scripts' within the Mashup Server directory.

Step 3:

That's it, the 'hello world' service is now live, exposing a single operation 'hello' that returns some XML.  But let's try it out to make sure it's working properly.  Open up the WSO2 Mashup Server web-based console (typically at https://localhost:7443/) and look for 'helloworld' in the list of the available mashups.


Click the 'Try helloworld' link in the mashup widget or try typing the tryit URL (typically at http://127.0.0.1:7762/services/helloworld?tryit) in the browser, and you will get a web-based client that can interact with the Web service. In this case just click the button titled hello >> to invoke the hello operation. The response is illustrated below:



The Helloworld mashup widget also contains many helpful resources.



Adding an user Interface for your service

When a service is deployed, Mashup server automatically creates a folder to store the resources that belong to the service. This folder is named as "{service javascript file name}.resources". You can install a custom user interface for your service by creating a folder named "www" under the above mentioned resources folder and placing the necessary files under the created "www" folder. This user interface will appear when you point your browser to the End Point Reference of the service (eg: http://localhost:7762/services/helloworld). Refer to the deploying Javascript services for more details on the mashup server deployment structure.

Please refer to "writing hello world client" for more information about creating AJAX clients for the mashup services deployed in the WSO2 mashup server.

Automatically Generated Resources

Just by virtue of deploying the service, the WSO2 mashup server generates a number of descriptive artifacts and tools to make it easy to consume the web service you've just created. These artifacts are linked from the management console for the service, or can be accessed directly from the endpoint URI associated with the service. Typically the endpoint URI is http://{host ip}:7762/services/{service name}, where the service name is by default the name of the JavaScript file defining the service (minus the '.js'). By appending one of the following queries to the endpoint URI, different artifacts and tools can be accessed:

?wsdl2 WSDL 2.0 description of the service
?wsdl WSDL 1.1 description of the service
?xsd XML Schema description of the service
?stub JavaScript or E4X stub for accessing the service
?tryit Ajax client for simple, generic interactions with the service
?source The JavaScript source code for the service
?doc API Documentation for the service