Coder Social home page Coder Social logo

pb2204 / js-http Goto Github PK

View Code? Open in Web Editor NEW
20.0 1.0 1.0 137 KB

A simple JavaScript HTTP request library for making GET and POST requests using the Fetch API.

Home Page: https://www.npmjs.com/package/https-node.js

License: MIT License

JavaScript 100.00%
collaborate communityexchange ghdesktop github github-campus-experts github-codespaces github-pages gitkraken gitlens jetbrains

js-http's Introduction

JS-HTTP

A simple JavaScript HTTP request library for making GET, POST, PUT, DELETE, OPTIONS, HEAD, CONNECT, TRACE, and PATCH requests using the Fetch API.

Installation

You can install JS-HTTP using npm:

npm install https-node.js

Project Structure

The project structure is organized as follows:

js-http/
|-- dist/
|-- src/
|   |-- js-http.js
|-- examples/
|   |-- index.html
|-- tests/
|   |-- test-js-http.js
|-- CODE_OF_CONDUCT.md
|-- CONTRIBUTING.md
|-- LEARN.md
|-- README.md
|-- LICENSE
|-- package.json
|-- webpack.config.js
|-- .gitignore
  • dist/: Contains the distribution version of the library.
  • src/: Contains the source code of the library.
  • examples/: Includes HTML examples demonstrating library usage.
  • tests/: Contains test files for the library.
  • CODE_OF_CONDUCT.md: Guidelines for community behavior.
  • CONTRIBUTING.md: Information on how to contribute to the project.
  • LEARN.md: Additional resources and learning materials.
  • README.md: This README file.
  • LICENSE: The license file for the project.
  • package.json: Configuration file for npm.
  • webpack.config.js: Configuration for bundling the library.
  • .gitignore: Specifies files and directories to be ignored by Git.

Overview

JS-HTTP is a lightweight JavaScript library that simplifies making various HTTP requests in your web applications. It provides a straightforward API for making GET, POST, PUT, DELETE, OPTIONS, HEAD, CONNECT, TRACE, and PATCH requests using the Fetch API.

Examples

You can find usage examples in the examples/ directory. To run the examples, open the HTML files in your browser.

Usage

Here's how you can use JS-HTTP in your JavaScript code:

// Import the JS-HTTP library
const JSHTTP = require('https-node.js);

Make a GET request

JSHTTP.get('https://jsonplaceholder.typicode.com/posts/1')
  .then(response => {
    console.log('GET Response:', response);
  })
  .catch(error => {
    console.error('GET Error:', error);
  });

Make a POST request

const data = { userId: 1, id: 101, title: 'foo', body: 'bar' };
JSHTTP.post('https://jsonplaceholder.typicode.com/posts', data)
  .then(response => {
    console.log('POST Response:', response);
  })
  .catch(error => {
    console.error('POST Error:', error);
  });

Make a PUT request

const putData = { userId: 1, id: 1, title: 'updated title', body: 'updated body' };
JSHTTP.put('https://jsonplaceholder.typicode.com/posts/1', putData)
  .then(response => {
    console.log('PUT Response:', response);
  })
  .catch(error => {
    console.error('PUT Error:', error);
  });

Make a DELETE request

JSHTTP.delete('https://jsonplaceholder.typicode.com/posts/101')
  .then(response => {
    console.log('DELETE Response:', response);
  })
  .catch(error => {
    console.error('DELETE Error:', error);
  });

Make an OPTIONS request

const optionsData = { someOption: 'value' };
JSHTTP.options('https://jsonplaceholder.typicode.com/some-resource', optionsData)
  .then(response => {
    console.log('OPTIONS Response:', response);
  })
  .catch(error => {
    console.error('OPTIONS Error:', error);
  });

Make a HEAD request

const headData = { someHeader: 'value' };
JSHTTP.head('https://jsonplaceholder.typicode.com/some-resource', headData)
  .then(response => {
    console.log('HEAD Response:', response);
  })
  .catch(error => {
    console.error('HEAD Error:', error);
  });

Make a CONNECT request

const connectData = { someData: 'value' };
JSHTTP.connect('https://jsonplaceholder.typicode.com/some-resource', connectData)
  .then(response => {
    console.log('CONNECT Response:', response);
  })
  .catch(error => {
    console.error('CONNECT Error:', error);
  });

Make a TRACE request

const traceData = { someData: 'value' };
JSHTTP.trace('https://jsonplaceholder.typicode.com/some

-resource', traceData)
  .then(response => {
    console.log('TRACE Response:', response);
  })
  .catch(error => {
    console.error('TRACE Error:', error);
  });

Make a PATCH request

const patchData = { someData: 'value' };
JSHTTP.patch('https://jsonplaceholder.typicode.com/some-resource', patchData)
  .then(response => {
    console.log('PATCH Response:', response);
  })
  .catch(error => {
    console.error('PATCH Error:', error);
  });

License

This project is licensed under the MIT License - see the LICENSE file for details.

Developer Details

Feel free to reach out for questions, feedback, or collaboration opportunities.

Happy Coding ๐Ÿš€

js-http's People

Contributors

pb2204 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

c-o-m-o-n

js-http's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.