/// namespace <%= prompts.prefix %>.core.util { 'use strict'; export interface IBackend { url: string; get(url: string, config?: ng.IRequestShortcutConfig): ng.IPromise; delete(url: string, config?: ng.IRequestShortcutConfig): ng.IPromise; post(url: string, data: any, config?: ng.IRequestShortcutConfig): ng.IPromise; put(url: string, data: any, config?: ng.IRequestShortcutConfig): ng.IPromise; } class Backend implements IBackend { static $inject = ['$http', constants.ID.AppConfig]; constructor(private $http: ng.IHttpService, private appConfig: constants.IAppConfig) { } get = (url: string, config?: ng.IRequestShortcutConfig) => this.unwrap(this.$http.get(this.prefix(url), this.headers(config))); delete = (url: string, config?: ng.IRequestShortcutConfig) => this.unwrap(this.$http.delete(this.prefix(url), this.headers(config))); post = (url: string, data, config?: ng.IRequestShortcutConfig) => this.unwrap(this.$http.post(this.prefix(url), data, this.headers(config))); put = (url: string, data, config?: ng.IRequestShortcutConfig) => this.unwrap(this.$http.put(this.prefix(url), data, this.headers(config))); get url() { return `${this.appConfig.BASE_URL}`; } private prefix = (url: string) => `${this.appConfig.BASE_URL}${url}`; private headers = (config?: ng.IRequestShortcutConfig) => { config = config || {}; config.headers = config.headers || {}; config.headers.Accept = 'application/json'; return config; }; private unwrap(p: ng.IHttpPromise) { return p.then(resp => resp.data); } } angular .module(ID.Backend, [ constants.Namespace ]) .service(ID.Backend, Backend); }