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

dedalo-ax

v1.0.18

Published

A lightweight alternative to Axios written in TypeScript.

Downloads

7

Readme

dedalo-ax

A lightweight alternative to Axios written in TypeScript

Just 823 bytes minified! 407 bytes minified + gzipped!

Check it out in bundlephobia:

For comparison, check Axios (29.5Kb):

Needless to say, Axios is much more advanced and has many more features but dedalo-ax covers most of Axios' use cases: simple HTTP requests using JSON as the content type ✅️

Node.js: Since version 18 Node.js includes the native fetch API, making node-fetch no longer necessary 👍️

Therefore, SSR usage will only work if Node.js is v18 or higher ⚠️ As for CSR (i.e., vanilla React, Svelte, Vue, etc.) the Node.js version won't matter 👍️

Install:

Using npm:

npm install dedalo-ax

Using yarn:

yarn add dedalo-ax

Using pnpm:

pnpm add dedalo-ax

Usage:

// Frontend Framework (React, Vue, Svelte, etc)
import { ax } from 'dedalo-ax';

// Vanilla JS (Browser)
// Remember: import statements must be inside script of type "module"
// <script type="module">
import { ax } from 'https://unpkg.com/dedalo-ax';

// Replace example url with your API url
const url = 'https://example.com/api/users';

// Data
const data = { username: 'foo' };
const updatedData = { username: 'bar' };

// Endpoint
const id = '1';
const endpoint = url + '/' + id;

// GET REQUEST
ax.get(url)
  .then(res => console.log(res));

// POST REQUEST
ax.post(url, data)
  .then(res => console.log(res));

// PUT REQUEST
ax.put(endpoint, updatedData)
  .then(res => console.log(res));

// DELETE REQUEST
ax.delete(endpoint)
  .then(res => console.log(res));

Abort Controller

The abort controller has a timespan of 5 seconds by default after which, if the server doesn't respond, the request is aborted.

Use with React:

import { useState, useEffect } from 'react';
import { ax } from 'dedalo-ax';

const { stringify } = JSON;
const url = 'https://jsonplaceholder.typicode.com/todos/1';

const App = () => {

  const [data, setData] = useState(null);

  useEffect(() => {
    ax.get(url).then(res => setData(res))
  }, []);
  
  return (
    <>
      <h1>dedalo-ax + React</h1>
      
      {(!data && !ax.error)
          ? <p>Loading...</p>
          : <>
              {(!data && ax.error) 
                ? <p>{ax.error}</p> 
                : <pre>{stringify(data)}</pre>
              }
            </>
      }    
    </>
  )
}

export default App

Use with Svelte:

<script>

  import { ax } from 'dedalo-ax';

  const { stringify } = JSON;
  const url = 'https://jsonplaceholder.typicode.com/todos/1';

  let data = ax.get(url);

</script>

<main>
  <h1>dedalo-ax + Svelte</h1>

  {#await data}
    <p>Loading...</p>
  {:then data}

    {#if data}
      <pre> {stringify(data)} </pre>
    {:else}
      <p> {ax.error} </p>
    {/if}
  
  {/await}
</main>

Use with Vue 3 (Composition API):

<script setup>
import { ref, watchEffect } from 'vue';
import { ax } from 'dedalo-ax';

const url = 'https://jsonplaceholderr.typicode.com/todos/1';

const data = ref(null);
const error = ref(null);
const loading = ref(false);

watchEffect(async () => {
  loading.value = true
  data.value = await ax.get(url)
  error.value = ax.error
  loading.value = false
})
</script>

<template>
  <main>
    
    <h1 class="title">dedalo-ax + Vue 3</h1>

    <p v-if="loading">Loading...</p>
    <p v-else-if="error">{{ error }}</p>
    <pre v-else>{{ data }}</pre>

  </main>
</template>

Use with Vue 2 (Options API):

<template>
  <main>
    
    <h1 class="title">dedalo-ax + Vue 2</h1>

    <p v-if="loading">Loading...</p>
    <p v-else-if="error">{{ error }}</p>
    <pre v-else>{{ data }}</pre>

  </main>
</template>

<script>

import { ax } from 'dedalo-ax';

const url = 'https://jsonplaceholder.typicode.com/todos/1';

export default {

  data: () => ({
    data: null, 
    error: null,
    loading: false,
  }),

  async created() {
    this.loading = true
    this.data = await ax.get(url)
    this.error = ax.error
    this.loading = false
  }
}
</script>