1.0.2 • Published 10 months ago

apiquest v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

ApiQuest

A lightweight API utility package for making HTTP requests in JavaScript.

Features

  • Supports multiple HTTP methods: GET, POST, PUT, PATCH, DELETE.
  • Handles various response types: JSON, XML, HTML, Plain Text, Blob, ArrayBuffer, CSV, and Form Data.
  • Simple error handling for HTTP errors.

Installation

You can install apiquest using npm:

npm install apiquest

Usage

Here's a quick example of how to use apiquest:

import apiQuest from "apiquest";

// Make a GET request
const fetchData = async () => {
  try {
    const response = await apiQuest.get("https://jsonplaceholder.typicode.com/todos/1");
    console.log(response);
  } catch (error) {
    console.error("Error fetching data:", error);
  }
};

fetchData();

HTTP Methods

GET Request

const data = await apiQuest.get("URL_HERE", { responseType: "json" });

POST Request

const data = await apiQuest.post("URL_HERE", { key: "value" });

PUT Request

const data = await apiQuest.put("URL_HERE", { key: "value" });

PATCH Request

const data = await apiQuest.patch("URL_HERE", { key: "value" });

DELETE Request

const response = await apiQuest.delete("URL_HERE");

Error Handling

The package throws errors for unsuccessful responses (status codes 4xx and 5xx). You can catch these errors as follows:

try {
  const response = await apiQuest.get("URL_HERE");
} catch (error) {
  console.error("Error:", error.message);
}

License

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

Author

KreativeND
GitHub Repository

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago