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

apira

v1.2.1

Published

Простая библиотека для формирования запросов. Является оберткой над axios

Downloads

31

Readme

APIra

Простая библиотека для формирования запросов. Является оберткой над axios

Основные возможности:

  • Хуки с интерфейсом middleware из koa (используется koa-compose)
  • Поддержка параметров url (спасибо pathToRegexp), например http://example.ru/users/:id
  • Возможность настройки конфига axios

Примеры

Создание:

import axios from 'axios'

const api = new APIra({ adapter: axios.create() })

Отправка запроса:

api
  .url('http://example.ru/users/:id')
  .params({
    id: 10
  })
  .query({
    filter_a: 'a',
    filter_b: 'b'
  })
  .GET()


api
  .url('http://example.ru/users/:id')
  .params({
    id: 1
  })
  .data({
    someData: 'someData'
  })
  .POST()

Использование хуков:

const logHook = async (ctx, next) => {
  console.log(ctx.response) // response == null
  await next()
  console.log(ctx.response) // response != null
}

api
  .hook(logHook)
  .url('http://example.ru/users/:id')
  .params({
    id: 10
  })
  .query({
    filter_a: 'a',
    filter_b: 'b'
  })
  .GET()

Наследование:

const api = new APIra({ adapter: axios.create() })

api
  .hook(logHook)
  .options({
    headers: {
      Authorization: 'Bearer SomeToken'
    }
  })

const api_v2 = api.extend()

API

APIra

APIra reference

import APIra from 'apira'

constructor

const api = new APIra([config], [hooks], [adapter])

| Параметр | Тип | Описание | |----------|--------------|----------| | config | object | Настройки axios | | hooks | function[] | Массив хуков | | adapter | function | Инстанс axios (или его mock) |

hook

api.hook([hookFn])

Добавляет хук в очередь

| Параметр | Тип | Описание | |----------|--------------|----------| | [hookFn] | Function | Принимаются только асинхронные функции |

url

api.url(urlPath)

Задает URL, по которому будет выполняться запрос

| Параметр | Тип | Описание | |----------|--------------|----------| | urlPath | string | URL-адрес |

params

api.params([options])

Задает параметры для URL'a.

| Параметр | Тип | Описание | |----------|--------------|----------| | [options] | object | Объект параметров |

Пример объекта параметров для https://example.ru/users/:userId/comments/:commentId:

{
  userId: id,
  commentId: id
}

query

api.query([queryOptions])

Создает из объекта queryString

| Параметр | Тип | Описание | |----------|--------------|----------| | [queryOptions] | object | Объект query параметров |

Пример query-объекта для foo=bar&abc=xyz:

{
  foo: 'bar',
  abc: 'xyz'
}

data

api.data([dataOptions])

Задает тело запроса

| Параметр | Тип | Описание | |----------|--------------|----------| | [dataOptions] | object | Объект data параметров |

Пример data-объекта:

{
  user_id: id
}

options

api.options([options])

Позволяет дополнить дефолтный конфиг axios

| Параметр | Тип | Описание | |----------|--------------|----------| | [options] | object | Объект axios параметров |

Пример объекта axios параметров:

{
  baseURL: '/api/v1/'
}

GET | POST | PUT | DELETE

api
  .url('http://example.ru/users/:id')
  .GET()

Функции вызова соответсвующих методов

inspect

api.inspect()

Возвращает конфиг axios

extend

const api_v2 = api.extend()

Позволяет скопировать инстанс, сохраняя adapter, config и hooks

TODO

  • Оптимизировать сборку