{"id":17676,"library":"grunt-http","title":"Grunt HTTP Request Task","description":"grunt-http is a Grunt plugin that facilitates sending HTTP requests and handling their responses within a Grunt build workflow. It acts as a wrapper around the popular, but now deprecated, `request` module. The current stable version is 2.3.3, but the package has not seen updates since 2018, indicating it is no longer actively maintained. Its core functionality allows developers to configure various HTTP methods, headers, query parameters, and request bodies, along with options to save responses to files or process them via callbacks. Unlike modern fetch APIs, it integrates directly into the Grunt task runner, making it suitable for older build systems still relying on Grunt for network operations. Its primary differentiator is its deep integration with Grunt's configuration and file handling system, inheriting the `request` module's extensive options for HTTP client behavior.","status":"abandoned","version":"2.3.3","language":"javascript","source_language":"en","source_url":"git://github.com/johngeorgewright/grunt-http","tags":["javascript","gruntplugin","request","http"],"install":[{"cmd":"npm install grunt-http","lang":"bash","label":"npm"},{"cmd":"yarn add grunt-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add grunt-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency, required to run Grunt tasks.","package":"grunt","optional":false},{"reason":"Optional dependency for handling `multipart/form-data` requests.","package":"form-data","optional":true}],"imports":[{"note":"Grunt plugins are loaded via `loadNpmTasks` and configured within `initConfig`, not directly imported as JavaScript modules.","wrong":"const http = require('grunt-http'); // Incorrect for Grunt tasks","symbol":"http task configuration","correct":"grunt.initConfig({\n  http: {\n    // ... task configuration ...\n  }\n});"},{"note":"This line must be present in your Gruntfile.js to make the `http` task available to Grunt.","wrong":"import 'grunt-http'; // Incorrect syntax for loading Grunt plugins","symbol":"load plugin","correct":"grunt.loadNpmTasks('grunt-http');"},{"note":"Most request-related options, including `url` or `uri`, `method`, `headers`, `body`, and `qs`, must be placed within the `options` object for each task target.","wrong":"http: {\n  myTask: {\n    url: 'https://api.example.com/data' // 'url' must be nested under 'options'\n  }\n}","symbol":"Task Options (e.g., url)","correct":"http: {\n  myTask: {\n    options: {\n      url: 'https://api.example.com/data'\n    }\n  }\n}"}],"quickstart":{"code":"module.exports = function(grunt) {\n  grunt.initConfig({\n    pkg: grunt.file.readJSON('package.json'),\n    http: {\n      getData: {\n        options: {\n          url: 'https://jsonplaceholder.typicode.com/posts/1',\n          method: 'GET',\n          headers: {\n            'User-Agent': 'Grunt-HTTP-Client'\n          },\n          callback: function(error, response, body) {\n            if (error) {\n              grunt.log.error('HTTP Error:', error.message);\n            } else if (response.statusCode >= 400) {\n              grunt.log.warn('API responded with status %d: %s', response.statusCode, body);\n            } else {\n              grunt.log.ok('Fetched data successfully:\\n', body.substring(0, 100) + '...');\n            }\n          }\n        },\n        // Optionally save the response to a file\n        dest: 'dist/post-data.json'\n      },\n      postData: {\n        options: {\n          url: 'https://jsonplaceholder.typicode.com/posts',\n          method: 'POST',\n          json: {\n            title: 'foo',\n            body: 'bar',\n            userId: 1\n          },\n          callback: function(error, response, body) {\n            if (!error && response.statusCode === 201) {\n              grunt.log.ok('Posted data successfully:', JSON.stringify(body));\n            } else if (error) {\n               grunt.log.error('POST Error:', error.message);\n            } else {\n              grunt.log.warn('POST failed with status %d: %s', response.statusCode, JSON.stringify(body));\n            }\n          }\n        }\n      }\n    }\n  });\n\n  grunt.loadNpmTasks('grunt-http');\n\n  grunt.registerTask('default', ['http:getData', 'http:postData']);\n};","lang":"javascript","description":"This Gruntfile example demonstrates how to configure and run both GET and POST HTTP requests using grunt-http. It fetches data from a public API, logs the response, and optionally saves it to a file, then sends a POST request with JSON data and logs the outcome."},"warnings":[{"fix":"Consider migrating to a modern, actively maintained HTTP client like `axios`, `node-fetch`, or Node.js's built-in `http`/`https` modules, and replace `grunt-http` with a custom Grunt task or a different build tool if HTTP requests are critical to your build process.","message":"The underlying `request` library, which grunt-http heavily relies upon, has been officially deprecated since February 2020. This means it no longer receives updates, including security fixes or new features, posing potential security risks and compatibility issues with modern Node.js environments.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Ensure your project's Grunt and Node.js versions match the plugin's compatibility range if you must continue using it. Ideally, update your build system away from such outdated dependencies.","message":"grunt-http supports Grunt versions `>=0.4.1` and Node.js versions `>=0.8.0`. These are very old requirements, and running this plugin with recent versions of Grunt or Node.js may lead to unexpected behavior or incompatibilities, especially given the `request` library's deprecation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Run `npm install form-data --save-dev` if you intend to send `multipart/form-data` requests.","message":"When using `multipart/form-data`, the `form-data` package is an optional dependency that must be installed separately. Failing to install it will result in errors when attempting multipart requests.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If working with HTTPS, always keep `strictSSL` set to `true` (its default). For self-signed certificates in development, use `rejectUnauthorized: false` with caution, or configure an appropriate `agent` with your custom certificate authority if necessary.","message":"The `request` module (and by extension `grunt-http`) handles SSL certificate validation with the `strictSSL` option. Relying on older or deprecated HTTP clients can introduce vulnerabilities if not properly configured or if the underlying client has known security flaws that are no longer patched.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Add `grunt.loadNpmTasks('grunt-http');` to your Gruntfile.js after `grunt.initConfig()`.","cause":"The `grunt-http` plugin has not been correctly loaded in the Gruntfile.js.","error":"Warning: Task \"http\" not found. Use --force to continue."},{"fix":"Ensure that all components of the URL that are not part of the path structure (e.g., query parameters values) are properly URL-encoded using `encodeURIComponent()` if constructed dynamically.","cause":"The `url` or `uri` option contains special characters (like spaces) that are not URL-encoded.","error":"TypeError: Request path contains unescaped characters"},{"fix":"Provide a valid `url` or `uri` string within the `options` object for your `http` task target. For example: `options: { url: 'http://example.com' }`.","cause":"The `url` or `uri` option is missing or empty in your `http` task configuration.","error":"Error: options.uri is a required argument"},{"fix":"Verify the `url` option is correct, ensure the target server is running and accessible from the machine running Grunt, and check any local firewall configurations that might block the connection.","cause":"The HTTP request failed to connect to the specified server, often due to the server not running, incorrect URL, or firewall issues.","error":"Warning: 'Request' library error: connect ECONNREFUSED 127.0.0.1:80"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}