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

laravel-request

v1.2.29

Published

laravel-request

Downloads

785

Readme

laravel-request

Клиентская библиотека для работы с Laravel API. Поддерживает JSON и MessagePack, fluent-интерфейс в стиле Eloquent Query Builder.

Содержание


Установка

npm install laravel-request

Переменные окружения

| Переменная | Описание | |------------|----------| | REACT_APP_API_URL | Базовый URL API | | REACT_APP_DEBUG | true/false — логирование запросов и ответов |


Api

import { Api } from 'laravel-request';

| Метод | Описание | |-------|----------| | Api.get(controller, action, data) | GET | | Api.post(controller, action, data) | POST | | Api.put(controller, action, data) | PUT | | Api.patch(controller, action, data) | PATCH | | Api.delete(controller, action, id, data) | DELETE | | Api.getArg(controller, action, arg, data) | GET с аргументом в URL (например, index/123) | | Api.getUrl(url, data) | Прямой GET по URL |

URL формируется как: {domain}/api/v1/call/{controller}/{action}


ApiRequest

Два типа запросов

Выборка (список)Api.get(controller, 'index') или 'list'
Цепочка where(), select(), orderBy() и т.д. + метод выполнения:

| Метод | Результат | |-------|-----------| | first() | Первая страница | | all() | Все записи | | paginate(page, perPage) | Страница с пагинацией | | pluck(fields) | Только указанные поля | | call() | Без указания способа |

Действие — POST/PUT/PATCH/DELETE или GET одной записи (index)
Всегда завершается call().

Выборки: примеры и payload

Данные уходят в query-параметрах URL (или в теле POST, если длина >5000 символов).

При REACT_APP_API_URL=https://api.example.com URL формируется как https://api.example.com/api/v1/call/{controller}/{action}.

first():

URL: https://api.example.com/api/v1/call/product/index (GET)

Api.get('product', 'index')
  .select(['id', 'name', 'price'])
  .where('status', '=', 'active')
  .orderBy('created_at', 'desc')
  .first(success, error, final);
{
  "arguments": [],
  "query": [
    { "select": [["id", "name", "price"]] },
    { "where": ["status", "=", "active"] },
    { "orderBy": ["created_at", "desc"] }
  ],
  "data": { "paginateType": "first" },
  "unique_hash": "xK9...",
  "timestamp": 1708123456789
}

all():

URL: https://api.example.com/api/v1/call/product/index (GET)

Api.get('product', 'index')
  .where('category_id', '=', 1)
  .all(success, error, final);
{
  "arguments": [],
  "query": [{ "where": ["category_id", "=", 1] }],
  "data": { "paginateType": "all" },
  "unique_hash": "xK9...",
  "timestamp": 1708123456789
}

paginate():

URL: https://api.example.com/api/v1/call/product/index (GET)

Api.get('product', 'index')
  .whereIn('category_id', [1, 2, 3])
  .orderBy('name')
  .paginate(2, 15, success, error, final);
{
  "arguments": [],
  "query": [
    { "whereIn": ["category_id", [1, 2, 3]] },
    { "orderBy": ["name"] }
  ],
  "data": {
    "paginateType": "paginate",
    "page": 2,
    "perPage": 15
  },
  "unique_hash": "xK9...",
  "timestamp": 1708123456789
}

pluck():

URL: https://api.example.com/api/v1/call/product/index (GET)

Api.get('product', 'index')
  .pluck(['id', 'name'], success, error, final);
{
  "arguments": [],
  "query": [],
  "data": {
    "paginateType": "pluck",
    "fields": ["id", "name"]
  },
  "unique_hash": "xK9...",
  "timestamp": 1708123456789
}

first() — сложный (whereHas, with):

URL: https://api.example.com/api/v1/call/product/index (GET)

Api.get('product', 'index')
  .select(['id', 'name', 'price'])
  .where('status', '=', 'active')
  .whereHas('category', (q) => q.where('visible', true))
  .with(['images', 'category'])
  .orderBy('created_at', 'desc')
  .first(success, error, final);
{
  "arguments": [],
  "query": [
    { "select": [["id", "name", "price"]] },
    { "where": ["status", "=", "active"] },
    { "whereHas": ["category", { "query": [{ "where": ["visible", true] }] }] },
    { "with": [["images", "category"]] },
    { "orderBy": ["created_at", "desc"] }
  ],
  "data": { "paginateType": "first" },
  "unique_hash": "xK9...",
  "timestamp": 1708123456789
}

getArg() (например, index/123):

URL: https://api.example.com/api/v1/call/user/index (GET, id=123 в payload)

Api.getArg('user', 'index', 123).call(success, error, final);
{
  "arguments": [123],
  "query": [],
  "data": {},
  "unique_hash": "xK9...",
  "timestamp": 1708123456789
}

Действия: call()

// URL: https://api.example.com/api/v1/call/user/store (POST)
Api.post('user', 'store', { name: 'John', email: '[email protected]' })
  .call(success, error, final);

// URL: https://api.example.com/api/v1/call/user/update (PUT)
Api.put('user', 'update', { id: 1, name: 'John' })
  .call(success, error, final);

// URL: https://api.example.com/api/v1/call/user/destroy (DELETE, id=123 в payload)
Api.delete('user', 'destroy', 123)
  .call(success, error, final);

// URL: https://api.example.com/api/v1/call/user/index (GET, id=123 в payload)
Api.getArg('user', 'index', 123)
  .call(success, error, final);

Отключение уведомлений

Api.get('product', 'index').withoutNotify().first(success, error, final);

Api.post('user', 'store', data)
  .withoutNotify((status) => status !== 422)
  .call(success, error, final);

Прямой вызов по URL

Api.getUrl('https://api.example.com/custom/endpoint')
  .callUrl(success, error, final);

Отмена запроса

const request = Api.get('product', 'index').first(success, error, final);
request.getSource().cancel();

Лицензия

MIT © Abramov Oleg