HTTP service for sending requests to backend endpoints

The HttpClient is the primary interface for making HTTP requests within the Lime platform.

By default, all requests expect JSON responses. For other content types (text, binary data, etc.), set the responseType in HttpOptions.

All methods throw HttpResponseError on HTTP errors (4xx, 5xx status codes).

Example

Basic GET request for JSON data

const http = platform.get(PlatformServiceName.Http);
const data = await http.get('my_addon/endpoint');
console.log(data);

Example

POST request with data and query parameters

const http = platform.get(PlatformServiceName.Http);
const response = await http.post(
'my_addon/users',
{ name: 'John Doe', email: 'john@example.com' },
{ params: { notify: 'true' } }
);

Example

Error handling with HttpResponseError

const http = platform.get(PlatformServiceName.Http);
try {
const data = await http.get('my_addon/endpoint');
} catch (error) {
if (error.name === 'HttpResponseError') {
console.error(`HTTP ${error.status}: ${error.message}`);
console.error('Response:', error.response);
}
}

Example

Downloading a file as blob

const http = platform.get(PlatformServiceName.Http);
const blob = await http.get('my_addon/download/report.pdf', {
responseType: 'blob'
});
const url = URL.createObjectURL(blob);
window.open(url);

Hierarchy

  • HttpClient

Methods

Methods

  • Sends a DELETE request to remove data from the server

    Returns

    Promise resolving to the response data. Type depends on responseType

    Throws

    HttpResponseError when the server responds with an error status (4xx, 5xx)

    Example

    const http = platform.get(PlatformServiceName.Http);
    await http.delete('my_addon/users/123');

    Parameters

    • url: string

      Relative URL to the resource (e.g., 'my_addon/users/123')

    • Optional options: HttpOptions

      Optional HttpOptions for query parameters or headers

    Returns Promise<any>

  • Sends a GET request to retrieve data from the server

    Returns

    Promise resolving to the response data. Type depends on responseType

    Throws

    HttpResponseError when the server responds with an error status (4xx, 5xx)

    Example

    const http = platform.get(PlatformServiceName.Http);
    const users = await http.get('my_addon/users', {
    params: { active: 'true', limit: '10' }
    });

    Parameters

    • url: string

      Relative URL to the resource (e.g., 'my_addon/endpoint'). The URL is relative to the Lime CRM base URL.

    • Optional options: HttpOptions

      Optional HttpOptions for query parameters, headers, or response type

    Returns Promise<any>

  • Sends a PATCH request to partially update existing data on the server

    Returns

    Promise resolving to the response data. Type depends on responseType

    Throws

    HttpResponseError when the server responds with an error status (4xx, 5xx)

    Example

    const http = platform.get(PlatformServiceName.Http);
    await http.patch('my_addon/users/123', {
    email: 'newemail@example.com'
    });

    Parameters

    • url: string

      Relative URL to the resource (e.g., 'my_addon/users/123')

    • Optional data: object

      Partial payload containing only the fields to update

    • Optional options: HttpOptions

      Optional HttpOptions for query parameters, headers, or response type

    Returns Promise<any>

  • Sends a POST request to create new data on the server

    Returns

    Promise resolving to the response data. Type depends on responseType

    Throws

    HttpResponseError when the server responds with an error status (4xx, 5xx)

    Example

    const http = platform.get(PlatformServiceName.Http);
    const newUser = await http.post('my_addon/users', {
    name: 'Jane Smith',
    email: 'jane@example.com'
    });

    Parameters

    • url: string

      Relative URL to the resource (e.g., 'my_addon/endpoint')

    • Optional data: object

      Payload to send in the request body. Will be JSON-encoded by default.

    • Optional options: HttpOptions

      Optional HttpOptions for query parameters, headers, or response type

    Returns Promise<any>

  • Sends a PUT request to replace existing data on the server

    Returns

    Promise resolving to the response data. Type depends on responseType

    Throws

    HttpResponseError when the server responds with an error status (4xx, 5xx)

    Example

    const http = platform.get(PlatformServiceName.Http);
    await http.put('my_addon/users/123', {
    name: 'Jane Doe',
    email: 'jane@example.com',
    role: 'admin'
    });

    Parameters

    • url: string

      Relative URL to the resource (e.g., 'my_addon/users/123')

    • Optional data: object

      Complete payload to replace the existing resource

    • Optional options: HttpOptions

      Optional HttpOptions for query parameters, headers, or response type

    Returns Promise<any>