Socket
Book a DemoInstallSign in
Socket

webpack-loader-httpfile

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-loader-httpfile

Webpack loader for http file

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Webpack httpfile loader

Webpack loader that loads http file as ESM module.

How to get started?

  • Add dev dependency: npm install -D webpack-loader-httpfile
  • Modify webpack configuration(webpack.config.js) file to add httpfile loader and experiments.topLevelAwait as following:
const path = require('path');

module.exports = {
    module: {
        rules: [
            {
                test: /\.http$/,
                use: [
                    {
                        loader: path.resolve(__dirname, 'node_modules/webpack-loader-httpfile/index.js'),
                        options: {
                            verbose: true
                        },
                    },
                ],
            },
        ]
    },
    experiments: {
        topLevelAwait: true
    }
};
  • Create http file: demo.http
### get my ip
//@name myIp
GET https://httpbin.org/ip

### post test
//@name postTest
POST https://{{host}}/post
User-Agent: curl/7.47.0
Content-Type: application/json

{
  "name": "{{nick}}",
  "age": 42,
  "uuid": "{{$uuid}}",
  "demo": "hi` morning"
}
  • import http file and call HTTP requests in your code:
import {myIp, postTest} from './demo.http';

// simple http request
let response = await myIp();
console.log(await response.json());

// simple http post
response = await postTest({nick: "test", host: "httpbin.org", "uuid": "c8389930-1071-4b88-9676-30b9ba7f2343"});
console.log(await response.json());

References

  • Webpack: https://webpack.js.org/
  • esbuild-plugin-httpfile: https://github.com/servicex-sh/esbuild-plugin-httpfile

Keywords

webpack-loader

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts