├── .gitignore ├── webpack.config.js ├── STRUCTURE.md ├── package.json ├── LICENSE ├── dist └── js-http.min.js ├── CONTRIBUTING.md ├── DEBUG.log ├── CODE_OF_CONDUCT.md ├── tests └── test-js-http.js ├── docs └── index.html ├── src └── js-http.js ├── README.md └── LEARN.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | // webpack.config.js 2 | 3 | const path = require('path'); 4 | 5 | module.exports = { 6 | entry: './src/js-http.js', 7 | output: { 8 | filename: 'js-http.min.js', 9 | path: path.resolve(__dirname, 'dist'), 10 | }, 11 | mode: 'production', 12 | }; -------------------------------------------------------------------------------- /STRUCTURE.md: -------------------------------------------------------------------------------- 1 | ```bash 2 | js-http/ 3 | |-- dist/ 4 | | |-- js-http.min.js 5 | |-- src/ 6 | | |-- js-http.js 7 | |-- examples/ 8 | | |-- index.html 9 | |-- tests/ 10 | | |-- test-js-http.js 11 | |-- docs/ 12 | | |-- index.html 13 | |-- README.md 14 | |-- package.json 15 | |-- webpack.config.js 16 | |-- .gitignore 17 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "https-node.js", 3 | "description": "A simple HTTP request library for JavaScript.", 4 | "url": "https://github.com/pb2204/JS-HTTP", 5 | "keywords": [ 6 | "http request", 7 | "ajax request", 8 | "http server", 9 | "ajax server", 10 | "get method", 11 | "post method" 12 | ], 13 | "author": "Pabitra Banerjee", 14 | "contributors": [], 15 | "license": "MIT", 16 | "lib": ".", 17 | "main": "dist/js-http.min.js", 18 | "version": "1.1.9", 19 | "scripts": { 20 | "test": "mocha tests/test-js-http.js", 21 | "build": "webpack --mode production" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/pb2204/JS-HTTP" 26 | }, 27 | "devDependencies": { 28 | "chai": "^4.3.9", 29 | "chai-http": "^4.4.0", 30 | "mocha": "^10.2.0", 31 | "webpack": "^5.88.2", 32 | "webpack-cli": "^5.1.4" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Pabitra Banerjee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /dist/js-http.min.js: -------------------------------------------------------------------------------- 1 | (()=>{var t={82:t=>{t.exports=class{static async get(t){try{const r=await fetch(t);if(!r.ok)throw new Error(`HTTP error! Status: ${r.status}`);return await r.json()}catch(t){throw new Error(`GET request failed: ${t.message}`)}}static async post(t,r){try{const e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(t){throw new Error(`POST request failed: ${t.message}`)}}static async put(t,r){try{const e=await fetch(t,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(t){throw new Error(`PUT request failed: ${t.message}`)}}static async delete(t){try{const r=await fetch(t,{method:"DELETE"});if(!r.ok)throw new Error(`HTTP error! Status: ${r.status}`);return await r.json()}catch(t){throw new Error(`DELETE request failed: ${t.message}`)}}static async options(t,r){try{const e=await fetch(t,{method:"OPTIONS",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(t){throw new Error(`OPTIONS request failed: ${t.message}`)}}static async head(t,r){try{const e=await fetch(t,{method:"HEAD",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(t){throw new Error(`HEAD request failed: ${t.message}`)}}static async connect(t,r){try{const e=await fetch(t,{method:"CONNECT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(t){throw new Error(`CONNECT request failed: ${t.message}`)}}static async trace(t,r){try{const e=await fetch(t,{method:"TRACE",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(t){throw new Error(`TRACE request failed: ${t.message}`)}}static async patch(t,r){try{const e=await fetch(t,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(t){throw new Error(`PATCH request failed: ${t.message}`)}}}}},r={};!function e(a){var s=r[a];if(void 0!==s)return s.exports;var o=r[a]={exports:{}};return t[a](o,o.exports,e),o.exports}(82)})(); -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to JS-HTTP 2 | 3 | Welcome to the JS-HTTP project! We appreciate your interest in contributing. Before you get started, please take a moment to review the following guidelines. 4 | 5 | ## Table of Contents 6 | 7 | - [Getting Started](#getting-started) 8 | - [Contributor Workflow](#contributor-workflow) 9 | - [Reporting Issues](#reporting-issues) 10 | - [Feature Requests](#feature-requests) 11 | - [Code of Conduct](#code-of-conduct) 12 | 13 | ## Getting Started 14 | 15 | To start contributing to JS-HTTP, follow these steps: 16 | 17 | 1. Fork the JS-HTTP repository to your GitHub account. 18 | 2. Clone your forked repository to your local machine: 19 | 20 | ```bash 21 | git clone https://github.com/pb2204/js-http.git 22 | ``` 23 | 24 | 3. Create a new branch for your work: 25 | 26 | ```bash 27 | git checkout -b feature/your-feature 28 | ``` 29 | 30 | 4. Make your changes and commit them: 31 | 32 | ```bash 33 | git add . 34 | git commit -m "Add your meaningful commit message here" 35 | ``` 36 | 37 | 5. Push your changes to your forked repository: 38 | 39 | ```bash 40 | git push origin feature/your-feature 41 | ``` 42 | 43 | 6. Create a pull request (PR) to the `main` branch of the original JS-HTTP repository. 44 | 45 | 7. Wait for the maintainers to review your PR. Please be patient and responsive to feedback. 46 | 47 | 8. Once your PR is approved, it will be merged, and your contribution will be part of the project. 48 | 49 | ## Contributor Workflow 50 | 51 | - Always work on a feature branch, not the `main` branch. 52 | - Keep your forked repository up-to-date with the latest changes from the `main` branch of the original repository. 53 | - Write clear and concise commit messages. 54 | - Be respectful and constructive in all communication. 55 | 56 | ## Reporting Issues 57 | 58 | If you encounter any bugs, problems, or unexpected behavior, please help us by [reporting the issue](https://github.com/yourusername/js-http/issues) with the following details: 59 | 60 | - A clear and descriptive title. 61 | - A detailed description of the issue, including any error messages. 62 | - Steps to reproduce the issue. 63 | - Your environment (e.g., Node.js version, browser, operating system). 64 | 65 | ## Feature Requests 66 | 67 | We welcome ideas and suggestions for new features or improvements to JS-HTTP. Please open an issue and use the "Feature Request" template to provide details about your proposal. 68 | 69 | ## Code of Conduct 70 | 71 | By participating in this project, you agree to abide by the [Code of Conduct](CODE_OF_CONDUCT.md). We expect all contributors to maintain a respectful and inclusive environment for everyone. 72 | 73 | Thank you for considering contributing to JS-HTTP! Your contributions are valuable and help make this project better for everyone. -------------------------------------------------------------------------------- /DEBUG.log: -------------------------------------------------------------------------------- 1 | 0 verbose cli C:\Program Files\nodejs\node.exe C:\Users\rocks\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js 2 | 1 info using npm@9.6.0 3 | 2 info using node@v18.14.0 4 | 3 timing npm:load:whichnode Completed in 2ms 5 | 4 timing config:load:defaults Completed in 3ms 6 | 5 timing config:load:file:C:\Users\rocks\AppData\Roaming\npm\node_modules\npm\npmrc Completed in 4ms 7 | 6 timing config:load:builtin Completed in 4ms 8 | 7 timing config:load:cli Completed in 3ms 9 | 8 timing config:load:env Completed in 1ms 10 | 9 timing config:load:file:C:\Users\rocks\OneDrive\Desktop\JS-HTTP\.npmrc Completed in 1ms 11 | 10 timing config:load:project Completed in 8ms 12 | 11 timing config:load:file:C:\Users\rocks\.npmrc Completed in 2ms 13 | 12 timing config:load:user Completed in 2ms 14 | 13 timing config:load:file:C:\Users\rocks\AppData\Roaming\npm\etc\npmrc Completed in 1ms 15 | 14 timing config:load:global Completed in 1ms 16 | 15 timing config:load:setEnvs Completed in 2ms 17 | 16 timing config:load Completed in 24ms 18 | 17 timing npm:load:configload Completed in 24ms 19 | 18 timing npm:load:mkdirpcache Completed in 1ms 20 | 19 timing npm:load:mkdirplogs Completed in 1ms 21 | 20 verbose title npm version patch 22 | 21 verbose argv "version" "patch" 23 | 22 timing npm:load:setTitle Completed in 2ms 24 | 23 timing config:load:flatten Completed in 10ms 25 | 24 timing npm:load:display Completed in 12ms 26 | 25 verbose logfile logs-max:10 dir:C:\Users\rocks\AppData\Local\npm-cache\_logs\2023-09-28T04_46_40_927Z- 27 | 26 verbose logfile C:\Users\rocks\AppData\Local\npm-cache\_logs\2023-09-28T04_46_40_927Z-debug-0.log 28 | 27 timing npm:load:logFile Completed in 9ms 29 | 28 timing npm:load:timers Completed in 0ms 30 | 29 timing npm:load:configScope Completed in 0ms 31 | 30 timing npm:load Completed in 53ms 32 | 31 silly logfile start cleaning logs, removing 2 files 33 | 32 silly logfile done cleaning log files 34 | 33 timing command:version Completed in 84ms 35 | 34 verbose stack Error: Git working directory not clean. 36 | 34 verbose stack at module.exports (C:\Users\rocks\AppData\Roaming\npm\node_modules\npm\node_modules\libnpmversion\lib\enforce-clean.js:26:13) 37 | 34 verbose stack at async module.exports (C:\Users\rocks\AppData\Roaming\npm\node_modules\npm\node_modules\libnpmversion\lib\version.js:60:46) 38 | 34 verbose stack at async Version.change (C:\Users\rocks\AppData\Roaming\npm\node_modules\npm\lib\commands\version.js:77:21) 39 | 34 verbose stack at async module.exports (C:\Users\rocks\AppData\Roaming\npm\node_modules\npm\lib\cli.js:134:5) 40 | 35 verbose cwd C:\Users\rocks\OneDrive\Desktop\JS-HTTP 41 | 36 verbose Windows_NT 10.0.22000 42 | 37 verbose node v18.14.0 43 | 38 verbose npm v9.6.0 44 | 39 error Git working directory not clean. 45 | 40 verbose exit 1 46 | 41 timing npm Completed in 190ms 47 | 42 verbose code 1 48 | 43 error A complete log of this run can be found in: 49 | 43 error C:\Users\rocks\AppData\Local\npm-cache\_logs\2023-09-28T04_46_40_927Z-debug-0.log -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # JS-HTTP Code of Conduct 2 | 3 | ## Introduction 4 | 5 | JS-HTTP is an open-source project, and we welcome contributors from all backgrounds and experience levels. To ensure that our community is a safe and welcoming space for everyone, we have established this code of conduct. It outlines our expectations for all members of our community, including contributors, maintainers, and users. 6 | 7 | ## Our Pledge 8 | 9 | In the interest of fostering an open and welcoming environment, we pledge to: 10 | 11 | 1. Be respectful and considerate: We value and respect the contributions and ideas of all participants and will treat everyone with kindness and empathy. 12 | 13 | 2. Be inclusive: We will not tolerate discrimination, harassment, or exclusion based on race, color, religion, gender, sexual orientation, gender identity and expression, national origin, age, disability, or any other protected category. 14 | 15 | 3. Be collaborative: We encourage collaboration, constructive feedback, and open communication among community members. 16 | 17 | 4. Be patient and understanding: We understand that people have different skill levels and perspectives. We will be patient and supportive in our interactions with others. 18 | 19 | ## Expected Behavior 20 | 21 | We expect all members of the JS-HTTP community to: 22 | 23 | - Be respectful and considerate in all interactions, whether written or verbal. 24 | 25 | - Use inclusive language and avoid offensive, derogatory, or discriminatory comments and actions. 26 | 27 | - Be open to feedback and willing to learn from others. 28 | 29 | - Refrain from personal attacks, trolling, or harassment in any form. 30 | 31 | ## Unacceptable Behavior 32 | 33 | Unacceptable behavior includes, but is not limited to: 34 | 35 | - Offensive, derogatory, or discriminatory comments or actions. 36 | 37 | - Harassment, intimidation, or threats directed at anyone in the community. 38 | 39 | - Personal attacks or ad hominem criticism. 40 | 41 | - Trolling or intentionally disruptive behavior. 42 | 43 | - Publishing others' private information without consent. 44 | 45 | - Any other conduct that could reasonably be considered inappropriate in a professional setting. 46 | 47 | ## Reporting Violations 48 | 49 | If you witness or experience behavior that violates this code of conduct, please report it to the project maintainers immediately by sending an email to [maintainers@example.com]. All reports will be kept confidential. 50 | 51 | ## Enforcement 52 | 53 | Community members who engage in unacceptable behavior may be asked to stop or face temporary or permanent expulsion from the community at the discretion of the project maintainers. 54 | 55 | ## Acknowledgment 56 | 57 | This code of conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/version/2/0/code_of_conduct/), version 2.0. 58 | 59 | ## Questions or Concerns 60 | 61 | If you have questions or concerns regarding this code of conduct, please contact the project maintainer [Pabitra Banerjee](mailto:rockstarpabitra2204@gmail.com). 62 | 63 | We strive to create a positive and inclusive community, and we appreciate your cooperation in helping us achieve this goal. 64 | 65 | Thank you for being a part of the JS-HTTP community. -------------------------------------------------------------------------------- /tests/test-js-http.js: -------------------------------------------------------------------------------- 1 | // tests/test-js-http.js 2 | 3 | const chai = require('chai'); 4 | const chaiHttp = require('chai-http'); 5 | const JSHTTP = require('../src/js-http'); 6 | 7 | const { expect } = chai; 8 | 9 | chai.use(chaiHttp); 10 | 11 | describe('JSHTTP Library Tests', () => { 12 | it('should make a successful GET request', async () => { 13 | const response = await JSHTTP.get('https://jsonplaceholder.typicode.com/posts/1'); 14 | expect(response).to.be.an('object'); 15 | expect(response.id).to.equal(1); 16 | }); 17 | 18 | it('should make a successful POST request', async () => { 19 | const data = { userId: 1, id: 101, title: 'foo', body: 'bar' }; 20 | const response = await JSHTTP.post('https://jsonplaceholder.typicode.com/posts', data); 21 | expect(response).to.be.an('object'); 22 | expect(response.id).to.equal(101); 23 | }); 24 | 25 | // Test for PUT request 26 | it('should make a successful PUT request', async () => { 27 | const data = { userId: 1, id: 1, title: 'updated title', body: 'updated body' }; 28 | const response = await JSHTTP.put('https://jsonplaceholder.typicode.com/posts/1', data); 29 | expect(response).to.be.an('object'); 30 | expect(response.id).to.equal(1); 31 | expect(response.title).to.equal('updated title'); 32 | expect(response.body).to.equal('updated body'); 33 | }); 34 | 35 | // Test for DELETE request 36 | it('should make a successful DELETE request', async () => { 37 | const response = await JSHTTP.delete('https://jsonplaceholder.typicode.com/posts/101'); 38 | expect(response).to.be.an('object'); 39 | expect(response).to.deep.equal({}); 40 | }); 41 | 42 | // Test for OPTIONS request 43 | it('should make a successful OPTIONS request', async () => { 44 | const data = { someOption: 'value' }; // Replace with appropriate data if needed 45 | const response = await JSHTTP.options('https://jsonplaceholder.typicode.com/some-resource', data); 46 | expect(response).to.be.an('object'); 47 | }); 48 | 49 | // Test for HEAD request 50 | it('should make a successful HEAD request', async () => { 51 | const data = { someHeader: 'value' }; // Replace with appropriate data if needed 52 | const response = await JSHTTP.head('https://jsonplaceholder.typicode.com/some-resource', data); 53 | }); 54 | 55 | // Test for CONNECT request 56 | it('should make a successful CONNECT request', async () => { 57 | const data = { someData: 'value' }; // Replace with appropriate data if needed 58 | const response = await JSHTTP.connect('https://jsonplaceholder.typicode.com/some-resource', data); 59 | }); 60 | 61 | // Test for TRACE request 62 | it('should make a successful TRACE request', async () => { 63 | const data = { someData: 'value' }; // Replace with appropriate data if needed 64 | const response = await JSHTTP.trace('https://jsonplaceholder.typicode.com/some-resource', data); 65 | }); 66 | 67 | // Test for PATCH request 68 | it('should make a successful PATCH request', async () => { 69 | const data = { someData: 'value' }; // Replace with appropriate data if needed 70 | const response = await JSHTTP.patch('https://jsonplaceholder.typicode.com/some-resource', data); 71 | }); 72 | }); -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 |