# Class EndpointCaller

This class is in charge of calling an endpoint (eg: a SearchEndpoint).

This means it's only uses to execute an XMLHttpRequest (for example), massage the response and check if there are errors.

Will execute the call and return a Promise.

Call using one of those options :

- XMLHttpRequest for recent browser that support CORS, or if the endpoint is on the same origin.
- XDomainRequest for older IE browser that do not support CORS.
- Jsonp if all else fails, or is explicitly enabled.

## Index

### Methods

- call
- callUsingAjaxJsonP
- callUsingXDomainRequest
- callUsingXMLHttpRequest

### Properties

- useJsonp

### Constructors

- constructor

## Methods

### call

- call<T>(params: IEndpointCallParameters): Promise<ISuccessResponse<T>>

- - Defined in rest/EndpointCaller.ts :242

  Generic call to the endpoint using the provided IEndpointCallParameters.
  Internally, will decide which method to use to call the endpoint :
  -- XMLHttpRequest for recent browser that support CORS, or if the endpoint is on the same origin.
  -- XDomainRequest for older IE browser that do not support CORS.
  -- Jsonp if all else fails, or is explicitly enabled.

  #### Type parameters

  - #### T

  #### Parameters

  - ##### params: IEndpointCallParameters

    The parameters to use for the call

  #### Returns Promise<ISuccessResponse<T>>

  A promise of the given type

### callUsingAjaxJsonP

- callUsingAjaxJsonP<T>(requestInfo: IRequestInfo<T>): Promise<ISuccessResponse<T>>

- - Defined in rest/EndpointCaller.ts :427

  Call the endpoint using Jsonp https://en.wikipedia.org/wiki/JSONP
  Should be used for dev only, or for very special setup as using jsonp has a lot of drawbacks.

  #### Type parameters

  - #### T

  #### Parameters

  - ##### requestInfo: IRequestInfo<T>

    The info about the request

  #### Returns Promise<ISuccessResponse<T>>

### callUsingXDomainRequest

- callUsingXDomainRequest<T>(requestInfo: IRequestInfo<T>): Promise<ISuccessResponse<T>>

- - Defined in rest/EndpointCaller.ts :380

  Call the endpoint using XDomainRequest https://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx
  Used for IE8/9

  #### Type parameters

  - #### T

  #### Parameters

  - ##### requestInfo: IRequestInfo<T>

    The info about the request

  #### Returns Promise<ISuccessResponse<T>>

### callUsingXMLHttpRequest

- callUsingXMLHttpRequest<T>(requestInfo: IRequestInfo<T>, responseType?: string): Promise<ISuccessResponse<T>>

- - Defined in rest/EndpointCaller.ts :286

  Call the endpoint using XMLHttpRequest. Used internally by EndpointCaller.call.
  Will try internally to handle error if it can.
  Promise will otherwise fail with the error type.

  #### Type parameters

  - #### T

  #### Parameters

  - ##### requestInfo: IRequestInfo<T>

    The info about the request

  - ##### Default value responseType: string = "text"

    The responseType. Default to text. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType

  #### Returns Promise<ISuccessResponse<T>>

## Properties

### useJsonp

useJsonp: boolean

- Defined in rest/EndpointCaller.ts :203

Set this property to true to enable Jsonp call to the endpoint.
Be aware that jsonp is "easier" to setup endpoint wise, but has a lot of drawback and limitation for the client code.
Default to false.

type

  {boolean}

## Constructors

### constructor

- new EndpointCaller(options?: IEndpointCallerOptions): EndpointCaller

- - Defined in rest/EndpointCaller.ts :205

  Create a new EndpointCaller.

  #### Parameters

  - ##### Default value options: IEndpointCallerOptions = {}

    Specify the authentication that will be used for this endpoint. Not needed if the endpoint is public and has no authentication

  #### Returns EndpointCaller

### Hierarchy

- EndpointCaller

### Implements

- IEndpointCaller