0.0.3 • Published 1 year ago

@aid-kit/http v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Aid Kit - HTTP

npm version License: MIT

@aid-kit/http is a lightweight utility library designed to simplify HTTP requests in JavaScript using the fetch API. It provides easy-to-use methods for performing common HTTP operations like GET, POST, PUT, and DELETE, with built-in support for error handling, request configuration, and more.

Features

  • Easy HTTP Requests: Simplified methods for GET, POST, PUT, and DELETE requests.
  • Error Handling: Built-in error handling for HTTP status codes.
  • Custom Headers: Easily set global or per-request headers.
  • Request Interceptors: Modify requests before they are sent.
  • Response Interceptors: Process responses before they reach your application.
  • Timeouts: Set request timeouts to handle slow responses.

Installation

npm install @aid-kit/http
pnpm add @aid-kit/http
yarn add @aid-kit/http
bun add @aid-kit/http

Usage

const response = await http.get("https://api.example.com/data")

if (response.error) throw new Error(data.error)

console.log(response.data)

API Reference

new http(url)

Creates a new instance of the http class with the specified base URL.

  • url (string): The base URL for the HTTP requests.
const http = new http("https://api.example.com")
const response = await http.get("/data")

http.get(url, options)

Makes a GET request to the specified URL and returns a Promise that resolves with the response data.

  • url (string): The URL to make the request to.
  • options (object | undefined): An optional object containing additional options for the request.
    • search (object | undefined): An object containing the search parameters for the request.
const response = await http.get("https://api.example.com/data")
const response = await http.get("https://api.example.com/data", { search: { param1: "value1", param2: "value2" } })

http.post(url, options)

Makes a POST request to the specified URL and returns a Promise that resolves with the response data.

  • url (string): The URL to make the request to.
  • options (object | undefined): An optional object containing additional options for the request.
    • search (object | undefined): An object containing the search parameters for the request.
    • body (object | undefined): An object containing the body parameters for the request.

Example:

const response = await http.post("https://api.example.com/data")
const response = await http.post("https://api.example.com/data", { search: { param1: "value1", param2: "value2" } })
const response = await http.post("https://api.example.com/data", { body: { param1: "value1", param2: "value2" } })

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. Here are some ways you can contribute:

  • Bug Reports: If you find any bugs or unexpected behavior, please open an issue describing the problem.
  • Feature Requests: If you have ideas for new features or improvements, feel free to suggest them by opening an issue.
  • Code Contributions: Contributions to the codebase via pull requests are highly appreciated. Before submitting a pull request, please make sure to follow the contribution guidelines below.

Contribution Guidelines

  1. Fork the repository and clone it to your local machine.
  2. Create a new branch for your feature/fix: git checkout -b feature-name.
  3. Make changes and test them thoroughly.
  4. Ensure that your code follows the existing code style and conventions.
  5. Update the README and documentation if necessary.
  6. Commit your changes with descriptive commit messages.
  7. Push your branch to your fork: git push origin feature-name.
  8. Open a pull request to the main branch of the original repository.

Thank you for contributing to @aid-kit/http!

License

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

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago