I built a transport-independent foundation for JSON API clients in Perl
Описание и применение
Создана библиотека HTTP::API::Core, позволяющая писать переносимые клиентские приложения для JSON‑API в Perl, отделяя транспорт от политики повторных запросов, пагинации, лимитов и аутентификации.
Задача
API clients quickly grow from simple wrappers to complex infrastructure code handling retries, pagination, rate limits, authentication, etc.
Результат
Clients can focus on API logic while HTTP::API::Core handles retries, pagination, rate limits, and authentication in a transport-agnostic way, reducing code duplication and improving maintainability.
Рабочий процесс
- 1. Choose an HTTP transport (e.g., HTTP::Tiny).
- 2. Instantiate HTTP::API::Core with base_url, headers, timeout, and retry config.
- 3. Call API methods (get, post, etc.) via the core instance.
- 4. Use core’s json() to decode responses.
- 5. For pagination, use paginate() with mode (cursor/page) and mapping options.
- 6. Handle rate limits via response->rate_limit().
- 7. Implement authentication by providing a hook or headers.
- 8. Keep service-specific client code minimal, delegating infrastructure to the core.
Доказательства
HTTP::API::Core sits above the transport layer.
Retries are more complicated than they look
- Дата записи: 2026-09-22T02:30:21.275Z