[
https://issues.apache.org/jira/browse/THRIFT-2820?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14389241#comment-14389241
]
Paul Smith commented on THRIFT-2820:
------------------------------------
Now you can generate an angularjs provider for each defined thrift service
{code:title=generate *_ngservice.js|borderStyle=solid}
thrift --gen js:angular=ngthriftApp ThriftTest.thrift # parameter is the
module name of your app
{code}
Additionally genrated source file:
{code:title=ThriftTest_ngprovider.js|borderStyle=solid}
angular.module('ngthriftApp').provider('ThriftTestClient', function
ThriftTestClientProvider(){
var url = '/ThriftTest';
this.setUrl = function(val) {
url = val;
};
this.$get = ['$http', function ThriftTestClientFactory($http) {
var config = {'$http' : $http};
var transport = new Thrift.Transport(url, config);
var protocol = new Thrift.Protocol(transport);
var client = new ThriftTest.ThriftTestClient(protocol);
return client;
}];
});
{code}
Configure the URL of the provider:
{code:title=Provider config|borderStyle=solid}
angular.module('ngthriftApp').config(["ThriftTestClientProvider",
function(ThriftTestClientProvider) {
// provide ThriftTestClient with proper server url
ThriftTestClientProvider.setUrl('/service'); // configure the service url
}]);
{code}
Now you can inject the "ThriftTestClient" into your controller/.. or use it in
the test-angular.js:
{code:title=Provider injection|borderStyle=solid}
angular.element($('body')).injector().get('ThriftTestClient');
{code}
(Make sure you have the scripts loaded in the correct order, see
test-angular.html)
> Implement an alternative Transport for JS using the AngularJS $http-service
> ---------------------------------------------------------------------------
>
> Key: THRIFT-2820
> URL: https://issues.apache.org/jira/browse/THRIFT-2820
> Project: Thrift
> Issue Type: New Feature
> Components: JavaScript - Library
> Affects Versions: 0.9.2
> Environment: AngularJS, Browser
> Reporter: David Sautter
> Priority: Minor
> Labels: features
> Original Estimate: 168h
> Remaining Estimate: 168h
>
> Since the architecture of the Thrift-library for Javascript-clients allows us
> to use custom Transports, I would like to have a Transport using the
> AngularJS $http-service. This would allow us to mock a Thrift Server in Tests
> as well as intercepting and customizing Thrift requests (e.g. authentication).
> The Tansport can be included into your AngularJS App via a module so that you
> can use it to instantiate your clients.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)