import QueryParam from "../../Uri/QueryParam" ; import ArgumentNullException from "typescript-dotnet-core/Exceptions/ArgumentNullException" ; import DisposableBase from "typescript-dotnet-core/Disposable/DisposableBase" ; import HttpMethodValue from "./HttpMethodValue" ; import HttpMethod from "./HttpMethod" ; import Uri from "../../Uri/Uri" ; import IUri from "../../Uri/IUri" ; import IHttpRequestAdapter from "./IHttpRequestAdapter" ; const NAME = 'HttpRequestFactory' ; /**
 * This class exposes a factory for making requests to prepared uri and params.
 */ export class HttpRequestFactory extends DisposableBase { protected _uriDefaults : Uri ; constructor ( private _http , uriDefaults ? ) { super ( NAME ) ; if ( ! _http ) throw new ArgumentNullException ( '_http' ) ; this . _uriDefaults = Uri . from ( uriDefaults ) ; } protected _onDispose ( ) { this . _http = < any > null ; this . _uriDefaults = < any > null ; } uri ( uri ) { const _ = this ; _ . throwIfDisposed ( ) ; const d = _ . _uriDefaults , u = Uri . from ( uri , d ) ; return d && u . equals ( d ) ? _ : new HttpRequestFactory ( _ . _http , u ) ; } params ( params ) { const _ = this ; _ . throwIfDisposed ( ) ; return _ . uri ( _ . _uriDefaults . updateQuery ( params ) ) ; } request < TResult > ( method , data ? ) { const _ = this ; _ . throwIfDisposed ( ) ; return _ . _http . request ( { method : method , uri : < any > _ . _uriDefaults , data : data } ) ; } get < TResult > ( ) { return this . request < TResult > ( HttpMethod . GET ) ; } put < TResult > ( ) { return this . request < TResult > ( HttpMethod . PUT ) ; } post < TResult > ( data ) { return this . request < TResult > ( HttpMethod . POST , data ) ; } 'delete' < TResult > ( ) { return this . request < TResult > ( HttpMethod . DELETE ) ; } } export default HttpRequestFactory ;