如何使用Angular调用Asp.NETWebAPI2.0HTTP批处理请求?

如何使用Angular调用Asp.NETWebAPI2.0HTTP批处理请求?,asp.net,api,angularjs,asp.net-web-api,Asp.net,Api,Angularjs,Asp.net Web Api,我在Asp.NETWebAPI2.0中使用Http批处理支持创建了一个示例WebAPI。描述该示例 如何使用Angular调用此批处理API?我知道这有点晚了,但我已经创建了Angular模块来启用HTTP批处理请求。模块就在这里,我在这里写了一篇关于它的博客文章 该模块对开发人员是透明的,因此,一旦您包含该模块并设置了批处理端点,对该服务的所有调用都将自动进行批处理。让我知道如果你需要任何帮助开始它 例如,下面3个http请求将自动批处理并转换为单个请求 var app = angular.m

我在Asp.NETWebAPI2.0中使用Http批处理支持创建了一个示例WebAPI。描述该示例


如何使用Angular调用此批处理API?

我知道这有点晚了,但我已经创建了Angular模块来启用HTTP批处理请求。模块就在这里,我在这里写了一篇关于它的博客文章

该模块对开发人员是透明的,因此,一旦您包含该模块并设置了批处理端点,对该服务的所有调用都将自动进行批处理。让我知道如果你需要任何帮助开始它

例如,下面3个http请求将自动批处理并转换为单个请求

var app = angular.module('httpBatchExample', ['jcs.angular-http-batch']);

app.config([  
    'httpBatchConfigProvider',
    function (httpBatchConfigProvider) {
        // setup some configuration to tell the module that requests to 
        // 'https://api.myapp.com' can be batched and send the batch request to https://api.myapp.com/batch
        httpBatchConfigProvider.setAllowedBatchEndpoint(
            'https://api.myapp.com',
            'https://api.myapp.com/batch');
    }
]);

app.controller('mainCtrl', [  
    '$scope',
    '$http',
    function ($scope, $http) {
        // Get the data as normal which will automatically be turned into a single HTTP request
        $http.get('https://api.myapp.com/products').then(function (data) {
            console.log('success 0 - ' + data.data);
        }, function (err) {
            console.log('error 0 - ' + err);
        });

        $http.get('https://api.myapp.com/products/2').then(function (data) {
            console.log('success 1 - ' + data.data);
        }, function (err) {
            console.log('error 1 - ' + err);
        });

        $http.put('https://api.myapp.com/products', {
            Name: 'Product X',
            StockQuantity: 300
        }).then(function (data) {
            console.log('success 2 - ' + data.data);
        }, function (err) {
            console.log('error 2 - ' + angular.fromJson(err));
        });
    }]);