# grunt-angularjs-thrift

> Thrift Angular Code Generator ============================= Make Thrift rpc calls to your Thrift http server, from javascript in a browser, in a website or cordova/phonegap app. This is a grunt module that compiles Thrift IDL into commonjs javascript, fo

Latest version **1.1.0** (published 2015-07-10) · 0 weekly downloads

## Install

```sh
npm install grunt-angularjs-thrift
pnpm add grunt-angularjs-thrift
yarn add grunt-angularjs-thrift
bun add grunt-angularjs-thrift
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2015-07-10 |
| First published | 2015-05-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8.0 |
| Dependencies | 9 |
| Known vulnerabilities | 0 (+7 in 4 direct dependencies) |
| Install scripts | no |
| Author | Kevin Massaroni |
| Maintainers | massaroni |

## Links

- npm: https://www.npmjs.com/package/grunt-angularjs-thrift
- npm.io page: https://npm.io/package/grunt-angularjs-thrift

## Dependencies (9)

- [path](https://npm.io/package/path.md) 0.11.14
- [merge](https://npm.io/package/merge.md) 1.2.0
- [shelljs](https://npm.io/package/shelljs.md) 0.3.0
- [fs-extra](https://npm.io/package/fs-extra.md) 0.12.0
- [node-uuid](https://npm.io/package/node-uuid.md) 1.4.2
- [underscore](https://npm.io/package/underscore.md) 1.6.0
- [concat-files](https://npm.io/package/concat-files.md) 0.1.0
- [precondition](https://npm.io/package/precondition.md) 1.0.0
- [recursive-readdir](https://npm.io/package/recursive-readdir.md) 1.2.1

## Recent versions

- 1.1.0 (latest) — 2015-07-10
- 0.1.1 — 2015-05-19
- 1.0.0 — 2015-05-19
- 0.1.0 — 2015-05-07

## README

Thrift Angular Code Generator
=============================
Make Thrift rpc calls to your Thrift http server, from javascript in a browser, in a website or cordova/phonegap app.  This is a grunt module that compiles Thrift IDL into commonjs javascript, for use with browserify or webpack.  The generated angularjs module generates an angular service for each Thrift service, at runtime.

Dependencies
============
Thrift: This is packaged with a pre-release snapshot of the Thrift 1.0 javascript runtime, from the [Apache Thrift](https://github.com/apache/thrift) repository, and so it depends on a Thrift 1.0 compiler, on the build machine.  You can build a Thrift 1.0 compiler from the Apache Thrift repository.  It will be backward compatible with Thrift 0.9.x IDL and server endpoints.


Example Gruntfile.js Configuration
==================================

```javascript

    module.exports = function (grunt) {
      // load the grunt plugin
      require('grunt-angularjs-thrift/compiler/grunt-thrift-generator')(grunt);

      // configure the grunt plugin
      grunt.initConfig({
        thriftcompiler: {
          deluxe: {
            files: [
              {
                src: 'app/src/thrift/**/*.thrift',
                dest: 'app/src/generated'
              }
            ],
            thriftSrcRoot: 'app/src/thrift/', // root directory of the above src path
            thriftBin: '~/dev/thrift/compiler/cpp/build/thrift', // this is your Thrift 1.0 compiler

            // (optional) with this property, it will generate angular services (at runtime, so you won't find any generated js files with angular services)
            angularServices: {
              rootEndpointUrl: '/thrift-api/v1/', // root uri path of all your thrift service endpoints (domain name is configured elsewhere)
              thriftRetryHandler: { // user-provided error handler, for thrift and http errors (see the example below)
                angularModule: 'thrift-retry',
                angularService: 'CustomThriftRetryHandler'
              }
            }
          },
          compileOnly: {
            files: [
              {
                src: 'app/src/thrift/**/*.thrift',
                dest: 'app/src/generated'
              }
            ],
            thriftSrcRoot: 'app/src/thrift/',
            thriftBin: '/Users/kmassaroni/dev/thrift/compiler/cpp/build/thrift'
          }
        }
      });

    };
```

Example: User-Provided Thrift Error Handler
==========================================

For example, always retry the same exact thrift call once, for whatever reason.

```javascript

    // app/src/thrift/thrift-retry-service.js

    require('angular');

    var thriftRetryModule = angular.module('thrift-retry', []);
    thriftRetryModule.service('CustomThriftRetryHandler', [function CustomThriftRetryHandler() {

      this.handleError = function handleError(thriftClient, reason, state) {
        if (state.callCount > 2) {
          thriftClient.reject(reason);
        } else {
          thriftClient.retry();
        }
      };

    }]);

```

Example: Load Thrift In Your App
================================

```javascript

    // app/src/thrift/thrift-services.js

    // the generated thrift js module returns a configuration object with instructions for generating angular services
    var generated = require('../generated/compiled_thrift');

    // the generated angular thrift services will depend on your custom angular service, for error handling
    require('./thrift-retry-service');

    // generate the angular thrift services, in the ngThriftServices module
    require('grunt-angularjs-thrift/runtime/ng-thrift-services')(generated);

    // your module must depend on the ngThriftServices module, provided by grunt-angularjs-thrift
    angular.module('my-module', ['ngThriftServices']);

    // the naming convention for angular thrift services is: [Thrift][your service name]. So, a thrift service named
    // SomethingService would have an angular thrift service name ThriftSomethingService
    angular.module('my-module').service('MyService', ['ThriftSomethingService', function (ThriftSomethingService) {
      ThriftSomethingService.callRoomService().then(function (response) {
        console.log('response from server:', response);
      }, function (reason) {
        console.log('thrift rpc call failed:', reason);
      });
    }]);

```

```idl

    // app/src/thrift/services.thrift

    service SomethingService {
     string callRoomService()
    }

```

TODO
====

1) more documentation
2) example project

---
_Source: https://npm.io/package/grunt-angularjs-thrift · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
