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

lite-api-client

v1.8.0

Published

A simple and versatile API client for making HTTP requests with support for all HTTP methods and custom headers.

Downloads

8

Readme

Lite API Client

A simple and versatile API client for making HTTP requests with support for all HTTP methods and custom headers.

Installation

Install the package using npm:

npm install lite-api-client

Usage

Here's how to use the Lite API Client in your project:

const LiteApiClient = require('lite-api-client');

// Initialize the API client
const api = new LiteApiClient('https://dummyjson.com');

// Set a default authorization token
api.setHeader('Content-Type', 'application/json');

// Making requests
(async () => {
    try {
        // GET request with query parameters
        const posts = await api.get('posts/search', { params: { q: 'love', limit: 1 } });
        console.log('GET /posts/search:', posts);

        // POST request with data
        const newPost = await api.post('/posts/add', JSON.stringify({
            title: 'I am in love with Lite API Client.',
            userId: '1'
        }));
        console.log('POST /posts/add:', newPost);

        // PUT request with data
        const updatedPost = await api.put('/posts/1', JSON.stringify({
            title: 'Lite API Client is easy to use.'
        }));
        console.log('PUT /posts/1:', updatedPost);

        // // DELETE request
        const deleteResponse = await api.delete('/posts/1');
        console.log('DELETE /posts/1:', deleteResponse);
    } catch (error) {
        console.error('Error:', error);
    }
})();

Using lite-api-client in a ReactJS Application

To integrate lite-api-client into your ReactJS application, follow the steps below.

Installation

First, ensure that the lite-api-client package is installed in your project:

npm install lite-api-client

or if you prefer using Yarn:

yarn add lite-api-client

Example Usage in a React Component

Here's an example of how to use lite-api-client in a React component to fetch data from an API:

import { useState, useEffect } from 'react';
import LiteApiClient from 'lite-api-client';

function App() {
  const [title, setTitle] = useState(null);

  useEffect(() => {
    // Create an instance of LiteApiClient with the base URL
    const apiClient = new LiteApiClient('https://dummyjson.com');

    const fetchData = async () => {
      try {
        // Make a GET request to the specified endpoint with query parameters
        const response = await apiClient.get('/posts/search', {
          params: { q: 'love', limit: 1 },
        });

        // Set the title state with the fetched data
        setTitle(response.posts[0].title);
      } catch (err) {
        // Handle errors
        console.log(err);
      }
    };

    fetchData();
  }, []);

  return (
    <>
      <h1>npm i lite-api-client</h1>
      <div className="card">Title: {title}</div>
    </>
  );
}

export default App;

API Methods

  • get(url, options): Make a GET request.
  • post(url, data, options): Make a POST request.
  • put(url, data, options): Make a PUT request.
  • patch(url, data, options): Make a PATCH request.
  • delete(url, options): Make a DELETE request.
  • head(url, options): Make a HEAD request.
  • options(url, options): Make an OPTIONS request.

Contributing

Contributions are welcome! Please open issues or submit pull requests on GitHub.

License

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