thrift/lib/js
henrique 5ba91f23bd THRIFT-2271 JavaScript: Support for Multiplexing Services
Patch: David Sautter
+ jslint fixes
2013-12-20 22:37:20 +01:00
..
src THRIFT-2271 JavaScript: Support for Multiplexing Services 2013-12-20 22:37:20 +01:00
test THRIFT-2190 Add the JavaScript thrift.js lib to the Bower registry 2013-09-20 19:38:03 +02:00
Gruntfile.js THRIFT-2190 Add the JavaScript thrift.js lib to the Bower registry 2013-09-20 19:38:03 +02:00
package.json THRIFT-2190 Add the JavaScript thrift.js lib to the Bower registry 2013-09-20 19:38:03 +02:00
README THRIFT-2190 Add the JavaScript thrift.js lib to the Bower registry 2013-09-20 19:38:03 +02:00

Thrift Javascript Library
=========================
This browser based Apache Thrift implementation supports
RPC using the JSON protocol over Http[s] with XHR.

License
-------
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

Example
-------
The listing below demonstrates a simple browser based JavaScript
Thrift client and Node.js JavaScript server for the HelloSvc service. 

### hello.thrift - Service IDL
    service HelloSvc {
        string hello_func(),
    }

### hello.html - Browser Client
    <!doctype html>
    <html lang="en">
    <head>
        <script src="thrift.js" type="text/javascript"></script>
        <script src="gen-js/HelloSvc.js" type="text/javascript"></script>
    </head>
    <body>
        <h1>Apache Thrift JavaScript Browser Client Demo</h1>
        <button id="btn">Get Message from Node Server</button>
        <script type="text/javascript">
            document.getElementById("btn").addEventListener("click", getMessage, false);
    
            function getMessage() {
                var transport = new Thrift.Transport("http://localhost:8585");
                var protocol  = new Thrift.Protocol(transport);
                var client = new HelloSvcClient(protocol);
                var msg = client.hello_func();
                document.getElementById("output").innerHTML = msg;
            }
        </script>
        <h2>Server Response: <div id="output"></div></h2>
    </body> 
    </html>

### hello.js - Node Server
    var thrift = require('thrift');
    var TJSONProtocol = require('thrift/protocol').TJSONProtocol;
    var HelloSvc = require('./gen-nodejs/HelloSvc.js');
    
    var call_counter = 0;
        
    var server = thrift.createHttpGetPostServer(HelloSvc, {
      hello_func: function(result) {
        console.log("Client call: " + (++call_counter));
        result(null, "Hello Apache Thrift for JavaScript " + call_counter);
      }
    }, {protocol: TJSONProtocol});
    
    server.listen(8585);