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 🙏

© 2026 – Pkg Stats / Ryan Hefner

next-laravel-apihelper

v1.1.7

Published

**Next Laravel API Helper** is a simple and efficient TypeScript library for interacting with Laravel APIs in Next.js and React.js applications. It provides a structured way to make HTTP requests with built-in authentication handling, error management, an

Readme

Next Laravel API Helper

Introduction

Next Laravel API Helper is a simple and efficient TypeScript library for interacting with Laravel APIs in Next.js and React.js applications. It provides a structured way to make HTTP requests with built-in authentication handling, error management, and support for common API operations.

Features

  • 🔹 Easy API Calls: Simplifies GET, POST, PUT, and DELETE requests.
  • 🔹 Authentication Support: Includes token-based authentication.
  • 🔹 Error Handling: Automatically catches and logs API errors.
  • 🔹 Customizable: Supports middleware and request modifications.
  • 🔹 Login Support: Allows user authentication and token management.
  • 🔹Detection: Auto-detect FormData and set Content-Type

Installation

npm install next-laravel-apihelper

Or using Yarn:

yarn add next-laravel-apihelper

Setup

1️⃣ Configure API Base URL

Ensure you set your API base URL in your .env.local file:

NEXT_PUBLIC_API_BASE_URL=https://your-laravel-api.com/api

OR REACT_APP_API_BASE_URL=https://your-laravel-api.com/api

2️⃣ Import and Use the Library

Example: Fetching Users

import { api } from "next-laravel-apihelper";

async function fetchUsers() {
  try {
    const users = await api.get("/users");
    console.log(users);
  } catch (error) {
    console.error("Error fetching users:", error);
  }
}

Example: Creating a User

async function createUser() {
  try {
    const response = await api.post("/users", {
      name: "John Doe",
      email: "[email protected]",
    });
    console.log("User Created:", response);
  } catch (error) {
    console.error("Error creating user:", error);
  }
}

Authentication

🔐 Logging in Users

To authenticate users, send their credentials to the login endpoint:

import { api } from "next-laravel-apihelper";

async function loginUser(email: string, password: string) {
  try {
    const response = await api.post("/login", { email, password });
    const token = response.token;
    api.setAuthToken(token); // Store token automatically
    console.log("Login successful!");
  } catch (error) {
    console.error("Login failed:", error);
  }
}

📌 Storing Authentication Token

To authenticate requests, include the token in the request headers:

Authentication Storage

Choose where you want the token to be stored:

  • localStorage (default) → Persistent even after browser is closed.
  • sessionStorage → Clears when browser tab or window is closed.
  • cookie → Stored in cookies. Set storage type (localStorage, sessionStorage, or cookie)
api.setAuthToken("your-access-token","storagetype");

This works alongside the automatic retrieval of the token from localStorage.

Error Handling

Errors are automatically handled, but you can also customize error messages:

api.setErrorHandler((error) => {
  console.error("Custom Error:", error.message);
});

Project Showcase 🎉

Check out the Admin Dashboard Project demonstrating this library in action! It features:

  • User Management (Add, Edit, Delete Users)
  • Tailwind Styled UI
  • API Integration with Laravel Backend

🔗 Live Demo
📂 FrontEnd Source Code 📂 BackEnd Source Code

Contributing

We welcome contributions! Feel free to fork this repository, submit issues, or create pull requests.

License

ISC License.