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

easycall

v0.0.57

Published

easyapi, is a framework to call api and store results painlessly.

Downloads

217

Readme

Easycall: Effortless API Integration in React

Easycall is your go-to solution for managing API interactions in React applications. It's designed from the ground up to ensure that every API call is streamlined, efficient, and intuitive. With Easycall, state management becomes second nature, and API calls feel like an integral part of your component tree.

🚀 Quick Start

Installation

Initiate your Easycall experience with a simple installation:

npm install easycall --save

🌟 Core Features

  • Simplified API Management: Navigate through your HTTP requests with unparalleled clarity and ease.
  • Dynamic Interceptors: Apply interceptors both globally or at the component level, refining each request and response to perfection.
  • Flexible Endpoints: Create a range of API endpoints effortlessly, each equipped with its specific methods.
  • State Management Reinvented: Enjoy the upcoming benefits of context-centric state management, where every API outcome has a dedicated space. (Coming Soon)

🔧 Setup Guide

Endpoint Configuration

Set the stage by configuring endpoints and methods tailored to your application's requirements:

import { CallerProvider } from "easycall"

ReactDOM.createRoot(document.getElementById("root")!).render(
  <CallerProvider
    easycallConfig={{
      baseURL: "https://jsonplaceholder.typicode.com/",
      headers: {
        "Content-type": "application/json; charset=UTF-8",
      },
      apiRoutes: [
        {
          key: "todos",
          method: "get",
          endpoint: "todos",
        },
        {
          key: "todo",
          method: "get",
          endpoint: "todos/{0}",
        },
      ],

      onBeforeRequest: (config) => {
        const token = localStorage.getItem("token")
        config.headers = token
          ? {
              ...config.headers,
              Authorization: `Bearer ${token}`,
            }
          : config.headers

        return config
      },

      onAfterResponse: (response) => {
        console.log("onAfterResponse", response)
        return response
      },
    }}
  >
    <App />
  </CallerProvider>,
)

🛠 Patterns of Usage

Unleash the Power of the Caller Hook

Harness the useCaller hook to make your API interactions intuitive while enabling precise argument passing and query string manipulations:

Fundamental Usage:

import { useCaller } from "easycall"

function SampleComponent() {
  const { call, data, error, loading } = useCaller((caller) => caller?.todos?.get?.())

  return loading ? (
    <LoadingComponent />
  ) : (
    <>
      {error && <ErrorAlert message={error.message} />}
      {data && <DataViewer data={data} />}
    </>
  )
}

Advanced Engagement with Arguments and Query Strings:

Envision fetching a specific todo item using an identifier like id. Easycall makes this easy by dynamically replacing endpoint placeholders:

import { useCaller } from "easycall"

export const DetailedComponent = () => {
  const { call, data, error, loading } = useCaller((caller) =>
    caller.todo.get({
      args: ["id"],
      queryString: "?numberOfItems=10",
    }),
  )

  return loading ? (
    <LoadingComponent />
  ) : (
    <>
      {error && <ErrorAlert message={error.message} />}
      {data && <DataViewer data={data} />}
    </>
  )
}

Stay Updated with Reactivity:

Easycall's useCaller hook is brilliantly reactive. It re-invokes the API call whenever a dependency changes, guaranteeing that your components are always in sync with the freshest data:

import { useState } from "react"
import { useCaller } from "easycall"

function DynamicComponent() {
  const [toggle, setToggle] = useState(false)

  const { call, data, error, loading } = useCaller((caller) => caller?.todos?.get?.(), {
    dependencies: [toggle],
  })

  return loading ? (
    <LoadingComponent />
  ) : (
    <>
      {error && <ErrorAlert message={error.message} />}
      {data && <DataViewer data={data} />}
      <button onClick={() => setToggle((prev) => !prev)}>Toggle Status</button>
    </>
  )
}

The Granular Approach

For enthusiasts who prefer an intricate touch, delve into a detailed strategy:

const apiRoutes: ApiRoute[] = [{ endpoint: "/todo", methods: ["Get", "Post"] }];

const callerInstance = createCaller(apiRoutes);
export callerInstance;

Note: Opting for this method means you forgo the luxuries of the useCaller hook and the context store provided by <CallerProvider />.

🔮 Upcoming Enhancements

  • Robust error management for a smoother UX.
  • Advanced caching strategies to accelerate response times.
  • Comprehensive oversight on request lifecycles.

Stay connected for future updates!

🤝 Join the Easycall Movement

Easycall thrives on community insights. Whether it's identifying bugs, brainstorming features, or enhancing the codebase, your input is invaluable:

  • Report Bugs: Discover an inconsistency? Report here.
  • Suggest Features: Conceived an innovation? Share here.
  • Contribute Code: Modify the repo, submit your enhancements, and create a pull request.