🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@breffjaun/usefetch

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@breffjaun/usefetch

A simple, reusable JavaScript package that simplifies the process of creating HTTP requests in web applications.

latest
Source
npmnpm
Version
1.1.3
Version published
Weekly downloads
15
1400%
Maintainers
1
Weekly downloads
 
Created
Source

useFetch

useFetch is a simple, reusable JavaScript package designed to streamline the process of making HTTP requests in web applications. It supports the four main HTTP methods (GET, POST, PATCH, PUT, DELETE) and provides a clean and flexible way to send requests and handle responses.

Installation

To use useFetch in your project, simply install it via npm:

npm i @breffjaun/usefetch

Usage

Import useFetch into your application and use the provided methods to send HTTP requests.

import useFetch from "@breffjaun/usefetch"

Documentation

Methods

  • get(url, func, options): Sends a GET request to the specified URL.
  • post(url, data, func, options): Sends a POST request to the specified URL with the provided data.
  • patch(url, data, func, options): Sends a PATCH request to the specified URL with the provided data.
  • put(url, data, func, options): Sends a PUT request to the specified URL with the provided data.
  • delete(url, func, options): Sends a DELETE request to the specified URL.

Options

The options parameter is optional and can be used to specify additional request options such as headers, credentials, cache behavior, etc.

Error Handling

useFetch provides basic error handling, including checking the response status and handling network errors.

Examples

// Example of a GET request
const url = "https://api.example.com/data";
const [data, setData] = useState({});
useEffect(() => {
  useFetch.get(url, setData);
}, []);

// Example of a POST request
const [user, setUser] = useState({});
const newUser = {
  firstName: "John",
  lastName: "Doe",
};
useEffect(() => {
  useFetch.post(url, newUser, setUser);
}, []);

Contributing

If you find bugs or have suggestions for improvements, please open an issue or submit a pull request.

License

useFetch is licensed under the MIT License. See the LICENSE file for more information.

Keywords

useFetch

FAQs

Package last updated on 20 Mar 2024

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