Skip to content

fetchJS is a lightweight JavaScript library designed to streamline the process of making HTTP requests in client-side applications. With fetchJS, developers can easily fetch resources from the internet without the hassle of dealing with complex XMLHttpRequest or fetch API configurations.

Notifications You must be signed in to change notification settings

chukwunonsoprosper/fetchJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

fetchJS

fetchJS is a lightweight JavaScript library designed to simplify the process of making HTTP requests in client-side applications. By leveraging the Fetch API, fetchJS provides developers with a clean and intuitive interface for fetching resources from the internet without the complexity of dealing with XMLHttpRequest or fetch API configurations.

Features:

  • Easy-to-Use Interface: With fetchJS, developers can make HTTP requests effortlessly using a simple and intuitive API. The library handles common tasks such as constructing fetch URLs, specifying HTTP methods, setting content types, and parsing response data, allowing developers to focus on building their applications.

  • Cross-Origin Resource Sharing (CORS) Support: fetchJS seamlessly handles Cross-Origin Resource Sharing (CORS) issues, enabling developers to fetch resources from external domains without encountering CORS restrictions.

  • Flexible Configuration: Developers have the flexibility to customize various aspects of their HTTP requests, including the URL, method, content type, and response type, to suit their specific requirements.

  • Error Handling: fetchJS includes robust error handling mechanisms to gracefully handle errors and provide informative error messages, ensuring smooth error recovery and debugging.

Usage:

Link the script tag to your html file

  <script type='module' src='./workspace.js'>

Make sure, the location to workspace.js, is linked correctly

To use fetchJS, simply install the library via npm:

npm i gofetchjs

Or clone the repo

git clone https://github.com/chukwunonsoprosper/fetchJS.git

Then import the fetchJS function into your JavaScript file and invoke it with the desired parameters:

import { fetchJS } from "./fetch.js";

//sample api request

let url = 'https://api.api-ninjas.com/v1/facts?X-Api-Key={YOUR_API_KEY}';
let method = 'GET';
let content_type = 'text/html';
let response_type = 'text';

fetchJS(url, method, content_type, response_type).then(result => {
    // Configure your API result here
    result = JSON.parse(result);
    console.log(result[0]['fact']);
});

fetchJS comes with a built in proxy server, to use this server, you import it to your working directory

import { fetchJsProxy } from "./proxy/fetchjsproxy.js";

//sample post method


let fetchJsproxyserver = fetchJsProxy();

async function fetchData() {
  let url = fetchJsproxyserver; // + API_URL

  let option = {
    /**
     * post request body, header, content-type, origin
     */
  }

  try {
      //all other code goes here
  } catch (error) {
    //handle error message
  }
}

fetchData();

Why fetchJS?

  • Saves Time and Effort: fetchJS simplifies the process of making HTTP requests, saving developers time and effort when implementing client-server communication in their applications.

  • Enhances Code Readability: With its clean and concise API, fetchJS improves code readability and maintainability, making it easier for developers to understand and collaborate on codebases.

  • Cross-Browser Compatibility: fetchJS is compatible with modern web browsers and provides consistent behavior across different browser environments, ensuring a smooth user experience for all users.

Whether you're building a simple web application or a complex single-page application (SPA), fetchJS is the perfect tool for handling HTTP requests with ease and efficiency.

check out the documentation

https://fetchjsdoc.vercel.app/

About

fetchJS is a lightweight JavaScript library designed to streamline the process of making HTTP requests in client-side applications. With fetchJS, developers can easily fetch resources from the internet without the hassle of dealing with complex XMLHttpRequest or fetch API configurations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published