javascript - Custom http headers for all actions from $resource -


i have troubles finding in docs, allows me define custom http headers actions of specific $resource, did know how this?

this want avoid

return $resource(main.dev + '/api/:entity/:action', '', {     saveuser: {         method: 'post',         params: {             entity: 'users',             action: 'register'         },         headers: {             api_key: main.api_key //same header          }     },     get:{         headers: {             api_key: main.api_key //same header          }       } }); 

you can httpinterceptor so:

define(['./app'], function (app) {   'use strict';   return app.factory('requestinterceptor', ['$log', function ($log) {     var requestinterceptor = {       request: function (config) {         $log.debug(config);          //your code here         //if config.url starts /api         //config.headers.push token          return config;       }     };     return requestinterceptor;   }]).config(['$httpprovider', function ($httpprovider) {     $httpprovider.interceptors.push('requestinterceptor');   }]); }); 

when config.url starts api insert headers config.headers.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -