{"id":16423,"library":"lil-http","title":"lil-http: Tiny Browser HTTP Client","description":"lil-http is a minimalist, full-featured HTTP client designed specifically for browser environments. It provides a simple, callback-based API for making HTTP requests (GET, POST, PUT, DELETE, PATCH, HEAD) using XMLHttpRequest (XHR) under the hood. Currently at version 0.1.17, the library prioritizes a tiny footprint (3 KB uncompressed, 1 KB gzipped) and broad browser compatibility (down to IE9, Chrome 5, Firefox 3) rather than modern features like Promises or the Fetch API. Its key differentiators were its small size and straightforward XHR wrapper API during its active development phase. However, the project appears to be unmaintained, with no recent releases or updates, making it unsuitable for new projects in modern web development stacks.","status":"abandoned","version":"0.1.17","language":"javascript","source_language":"en","source_url":"https://github.com/lil-js/http","tags":["javascript","lil","tiny","micro","http","request","xhr","ajax","https"],"install":[{"cmd":"npm install lil-http","lang":"bash","label":"npm"},{"cmd":"yarn add lil-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add lil-http","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package primarily supports CommonJS via `require()` for module loading, or global access.","wrong":"import http from 'lil-http';","symbol":"http","correct":"const http = require('lil-http');"},{"note":"If no module loader (like CommonJS `require`) is available, the library exposes itself globally as `lil.http`.","wrong":"import { http } from 'lil-http';","symbol":"lil.http","correct":"// When loaded via a <script> tag\nlil.http.get('/api/data', ...);"},{"note":"Individual HTTP methods like `get`, `post`, etc., are accessed directly from the imported or global `http` object.","wrong":"import { get } from 'lil-http';","symbol":"http.get","correct":"require('lil-http').get('/api/resource', options, callback);"}],"quickstart":{"code":"<html>\n<head>\n  <title>lil-http Quickstart</title>\n  <!-- Assuming lil-http.js is loaded, e.g., from a CDN or local file -->\n  <script src=\"https://cdn.rawgit.com/lil-js/http/0.1.17/http.js\"></script>\n</head>\n<body>\n  <h1>lil-http GET Request Example</h1>\n  <pre id=\"output\"></pre>\n\n  <script>\n    // Mock API endpoint (in a real scenario, this would be a server endpoint)\n    // For demonstration, we'll simulate a response after a delay.\n    const mockApiResponse = { message: 'Hello from lil-http!', version: '0.1.17' };\n\n    // Simulate a server response for '/sample.json'\n    function simulateFetch(url, options, callback) {\n      console.log(`Simulating GET request to ${url} with options:`, options);\n      setTimeout(() => {\n        if (url === '/sample.json') {\n          callback(null, { status: 200, data: mockApiResponse, headers: {} });\n        } else {\n          callback({ status: 404, message: 'Not Found' }, null);\n        }\n      }, 500);\n    }\n\n    // Override lil.http.get for this example to use our simulator\n    // In a real browser environment, lil.http.get would make a real XHR.\n    lil.http.get = simulateFetch;\n\n    lil.http.get('/sample.json', {\n      auth: { user: 'guest', password: 'password' },\n      headers: { 'X-Requested-With': 'lil-http' }\n    }, function (err, res) {\n      const outputDiv = document.getElementById('output');\n      if (err) {\n        console.error('Request failed:', err);\n        outputDiv.textContent = 'Error: ' + (err.message || 'Unknown error') + ' (Status: ' + err.status + ')';\n      } else if (res.status === 200) {\n        console.log('Response data:', res.data);\n        outputDiv.textContent = 'Success! Data: ' + JSON.stringify(res.data, null, 2);\n      } else {\n        outputDiv.textContent = 'Unexpected status: ' + res.status;\n      }\n    });\n  </script>\n</body>\n</html>","lang":"javascript","description":"This quickstart demonstrates a basic GET request using the globally exposed `lil.http` object, showing how to include authentication and custom headers, and handle the callback-based response."},"warnings":[{"fix":"For new development, use the native `fetch` API or a modern HTTP client library that supports Promises (e.g., `axios`). If bound to XHR, consider wrapping `lil-http` calls in `Promise` constructors.","message":"The package is effectively abandoned, last published as 0.1.17. It relies on XMLHttpRequest (XHR) and a callback-based API, which are considered legacy in modern JavaScript development, favoring Fetch API and Promises/async-await. Integrating it into a modern codebase would require significant effort or polyfills to align with contemporary asynchronous patterns.","severity":"breaking","affected_versions":"<=0.1.17"},{"fix":"Ensure `lil-http` is only used in client-side browser code. For Node.js, use built-in `http`/`https` modules or a Node.js-compatible client like `axios` or `node-fetch`.","message":"lil-http is a browser-only library and does not function in Node.js environments. It's built on `XMLHttpRequest`, which is a browser Web API.","severity":"gotcha","affected_versions":"<=0.1.17"},{"fix":"When possible, use CommonJS `require('lil-http')` in environments that support it (e.g., via a bundler like Webpack or Browserify). If relying on the global, be mindful of potential conflicts.","message":"The package uses a global fallback (`lil.http`) if `require()` is not available, which can lead to global namespace pollution or conflicts with other libraries using a similar `lil` object. This pattern is generally discouraged in modern module-based development.","severity":"gotcha","affected_versions":"<=0.1.17"},{"fix":"Install via npm: `npm install lil-http`. Be aware that even through npm, the underlying library is old and unmaintained.","message":"The README mentions installation via Bower and Component, which are package managers that are largely deprecated or unmaintained in favor of npm/yarn. While `lil-http` is available on npm, its primary suggested installation methods are outdated.","severity":"deprecated","affected_versions":"<=0.1.17"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure `<script src=\"path/to/http.js\"></script>` is placed before any code attempting to use `lil.http`. Alternatively, if using a bundler, ensure `const http = require('lil-http');` is correctly used and bundled.","cause":"The `lil` global object or `lil.http` property was not found. This usually happens when the library's script file (`http.js`) hasn't been loaded in the HTML before being accessed, or if CommonJS `require()` was attempted in an environment that doesn't support it and no global fallback was registered.","error":"TypeError: lil.http is undefined"},{"fix":"Check the network tab in browser developer tools for more specific errors. Verify the target URL is correct and accessible. Review browser console for CORS related errors. If the issue is CORS, the server configuration needs to be adjusted to allow requests from your origin, or a proxy should be used.","cause":"This error message (with status 0) often indicates a network error, such as the server being unreachable, a DNS resolution failure, a browser preventing the request due to security policies (e.g., CORS), or the request being aborted before it completes. Status 0 is XHR's way of indicating the request didn't even get to the point of receiving an HTTP status code.","error":"Error: Cannot perform the request: 0"},{"fix":"Configure the server (`http://example.com`) to include the `Access-Control-Allow-Origin` header with your origin (`http://localhost:8080`) or `*` for all origins (less secure). For local development, a proxy server can be used to bypass CORS.","cause":"The browser's Cross-Origin Resource Sharing (CORS) policy is blocking the request because the server at `http://example.com` did not send the necessary `Access-Control-Allow-Origin` header allowing requests from `http://localhost:8080`.","error":"Access to XMLHttpRequest at 'http://example.com/api' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."}],"ecosystem":"npm"}