npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-hitman

v1.1.1

Published

![Logo](https://github.com/Shikhar2525/HitMan/blob/main/logo-no-background.png?raw=true)

Downloads

27

Readme

React-HitMan

Logo

About

This custom React package offers a powerful and easy-to-use custom hook for handling API requests within your React applications. Whether you need to fetch data from an API or post data to it, this package streamlines the process and enhances the efficiency of your code.

Why HitMan ?

This npm package simplifies API calls in React using custom hooks. Here's why it's great:

  • Simplicity: Unlike larger frameworks such as RTK, this package is designed to be lightweight and easy to understand. You don't need to learn complex abstractions or deal with unnecessary overhead.

  • Ease of Use: The custom hooks provided by this package abstract away common API call patterns, making it quick and straightforward to integrate API functionality into your React components.

  • Flexibility: While it's simple to use out of the box, this package also offers customization options for those who need more control over their API calls. You can easily adapt it to suit your specific project requirements.

  • Performance: By keeping things lean and focused, this package ensures efficient API interactions without unnecessary bloat or overhead, resulting in better performance for your React applications.

If you're looking for a hassle-free way to handle API calls in React without the complexity of larger frameworks, give this package a try!

Features

It Simplifies the process of fetching data from APIs by providing a customizable hook. You can easily configure headers, query parameters, and other options.

  • Post Data: Includes a post request function within the hook, allowing you to send data to APIs effortlessly. Handle responses and errors seamlessly in your components.

  • Async/Await Support: Leverages modern JavaScript features like async/await, making asynchronous API calls clean and readable.

  • Error Handling: Built-in error handling ensures that your application gracefully manages API errors, providing a smooth user experience.

  • Customizable Options: Configure the API endpoint, request method, headers, and more based on your specific requirements.

Installation

Install api-hitman with npm

  npm install api-hitman

Props Description

useFetch , useMutation

| Props | Type | Description | | :---------- | :------------------------------------ | :---------------------------------------------------------------------------- | | baseUrl | string | Required. Your base url eg. localhost:8000 | | path | string | Required. API Path to hit eg. /products | | params | { [key: string]: string or number } | Optional. URL params eg. { id:123 , isNew:true } | | postData | object | Required in useMutation only. Data need to be passed { name: 'John' } |

Utils Props

| Props | Type | Description | | :------ | :-------- | :---------------------------------------------------- | | skip | boolean | Optional (defualt:false). Skip API call to happen |

Returned Variables

| Props | Type | Description | | :----------- | :--------- | :--------------------------------------------------- | | data | object | Returned data after successful API call | | isLoading | boolean | Current state of API loading | | refetch | Callback | Only for useFetch. Called to refetch current API | | error | Error | Returned error object when API call fails | | isError | boolean | Current state of Error |

Usage/Examples

import { useFetch } from "react-hitman-api";

export default function App() {
  const { data } = useFetch(
    {
      baseUrl: "https://jsonplaceholder.typicode.com",
      path: "/comments",
      params: { postId: 1 },
    },
    {
      skip: false,
    }
  );

  return (
    <main>
      {data?.map((item: any) => {
        return <h6>{JSON.stringify(item)}</h6>;
      })}
    </main>
  );
}

FAQ

Can it be used with any other JS frameworks

No

Can we contriubte to this package

Yes , please visit below given links to find github repository to raise a bug or contribute

Authors

Raise a (Bug / Feature Request)

For support, email [email protected] or raise Raise Bug / Feature Request at https://github.com/Shikhar2525/HitMan/issues

🔗 Links

linkedin

Badges

MIT License