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

http-dragon

v1.0.2

Published

For handling http request.

Downloads

33

Readme

Http Dragon

Hi! This module enhances HTTP request control effortlessly, offering greater control.

Basics

First, set up the base URL and APIs in the module.

Http.baseUrl = "https://jsonplaceholder.typicode.com";
Http.setApis({
  nameOfApi: "/todos/1",
});

Import the Http class and its instance to access HTTP verbs

import { Http, http } from "http-dragon";

Create a request object using an instance of the Http class.

const request = http.get(Http.apis.nameOfApi);
request.call({
  next: (res) => {
    console.log(res);
  },
  error: (error) => {
    console.log(error);
  },
});

Handling Request In React.js

This hook fetches initial data from an API and re-fetches when its dependencies change. It returns loading, error, and data states.

import { useRequest, http, Http } from "http-dragon";

const request = http.get(Http.apis.getInitialData);

function RequestExample() {
  const [loading, error, data] = useRequest(request, { dependencies: [] });
  //todo
}

Pipe function

Pipe uses to transform the response that get from api. and execute operators functions.

The map operator only works with data in array format. That example only works when the root of your response body contains the array.
import {Http,http,Operators} from "http-dragon"

const request = http.get(Http.apis.nameOfApi)
request.setPipe(Operators.map(el=>{
 el += "done";
 return el;
}))

request.call({
 next:(transformedData)=>{
 //todo
 },
 error:(error)=>{
  //todo
 },
 raw:(fullResponse)=>{
  //todo
 }
})

Using the key approach to transform the response.

const response = { yourKeyName:[] }
const request = http.get(Http.apis.nameOfApi);

request.setPipe(
  Operators.map("yourKeyName", (el) => {
    el += "done";
    return el;
  })
);

Using the nested keys.

const response = {
  yourKeyName:{
    allData:{
      finalData:["john"]
    }
  }
}
const request = http.get(Http.apis.nameOfApi);

request.setPipe(
  Operators.map("yourKeyName.allData.finalData", (el) => {
    el += "done";
    return el;
  })
);

Filter operator

The filter operator function is used for performing filtration on the array.That example only works when the root of your response body contains the array.

import {Http,http,Operators} from "http-dragon"

const request = http.get(Http.apis.nameOfApi)

request.setPipe(Operators.filter(el=>{
  if(el==="done"){
    return true;
  }
    return false
}))

request.call({
 next:(transformedData)=>{
 //todo
 },
 error:(error)=>{
  //todo
 },
 raw:(fullResponse)=>{
  //todo
 }
})

Using the key approach to filter the response.

const request = http.get(Http.apis.nameOfApi);

request.setPipe(
  Operators.filter("yourKeyName", (el) => {
    if(el === "done"){
      return true;
    }
    return false
  })
);

Using the nested keys.

const request = http.get(Http.apis.nameOfApi);

request.setPipe(
  Operators.filter("yourKeyName.allData.finalData", (el) => {
     if(el === "done"){
      return true;
    }
    return false
  })
);