Lime Web Components API Documentation - v6.24.0
    Preparing search index...

    Interface HttpClient

    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).

    Basic GET request for JSON data

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

    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' } }
    );

    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);
    }
    }

    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);
    interface HttpClient {
        delete(url: string, options?: HttpOptions): Promise<any>;
        get(url: string, options?: HttpOptions): Promise<any>;
        patch(url: string, data?: object, options?: HttpOptions): Promise<any>;
        post(url: string, data?: object, options?: HttpOptions): Promise<any>;
        put(url: string, data?: object, options?: HttpOptions): Promise<any>;
    }
    Index

    Methods

    • Sends a DELETE request to remove data from the server

      Parameters

      • url: string

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

      • Optionaloptions: HttpOptions

        Optional HttpOptions for query parameters or headers

      Returns Promise<any>

      Promise resolving to the response data. Type depends on HttpOptions.responseType

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

      const http = platform.get(PlatformServiceName.Http);
      await http.delete('my_addon/users/123');
    • Sends a GET request to retrieve data from the server

      Parameters

      • url: string

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

      • Optionaloptions: HttpOptions

        Optional HttpOptions for query parameters, headers, or response type

      Returns Promise<any>

      Promise resolving to the response data. Type depends on HttpOptions.responseType

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

      const http = platform.get(PlatformServiceName.Http);
      const users = await http.get('my_addon/users', {
      params: { active: 'true', limit: '10' }
      });
    • Sends a PATCH request to partially update existing data on the server

      Parameters

      • url: string

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

      • Optionaldata: object

        Partial payload containing only the fields to update

      • Optionaloptions: HttpOptions

        Optional HttpOptions for query parameters, headers, or response type

      Returns Promise<any>

      Promise resolving to the response data. Type depends on HttpOptions.responseType

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

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

    post

    • post(url: string, data?: object, options?: HttpOptions): Promise<any>

      Sends a POST request to create new data on the server

      Parameters

      • url: string

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

      • Optionaldata: object

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

      • Optionaloptions: HttpOptions

        Optional HttpOptions for query parameters, headers, or response type

      Returns Promise<any>

      Promise resolving to the response data. Type depends on HttpOptions.responseType

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

      const http = platform.get(PlatformServiceName.Http);
      const newUser = await http.post('my_addon/users', {
      name: 'Jane Smith',
      email: 'jane@example.com'
      });
    • Sends a PUT request to replace existing data on the server

      Parameters

      • url: string

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

      • Optionaldata: object

        Complete payload to replace the existing resource

      • Optionaloptions: HttpOptions

        Optional HttpOptions for query parameters, headers, or response type

      Returns Promise<any>

      Promise resolving to the response data. Type depends on HttpOptions.responseType

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

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