mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
5ba91f23bd
Patch: David Sautter + jslint fixes |
||
---|---|---|
.. | ||
src | ||
test | ||
Gruntfile.js | ||
package.json | ||
README |
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);