newtqnia / php
Official PHP SDK for the NewTqnia APIs. Retrieve bilingual technology news and integrate NewTqnia into PHP and Laravel applications.
Requires
- php: ^8.2
- php-http/discovery: ^1.20
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/simple-cache: ^2.0 || ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.68
- guzzlehttp/guzzle: ^7.9
- nyholm/psr7: ^1.8
- orchestra/testbench: ^9.0 || ^10.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
Suggests
- guzzlehttp/guzzle: Use Guzzle as the PSR-18 HTTP client.
- laravel/framework: Enable Laravel service provider, facade, configuration, and Blade component.
- symfony/http-client: Use Symfony HttpClient with PSR-18 support.
README
The official PHP SDK for the NewTqnia technology news API, providing structured access to bilingual technology news for PHP and Laravel applications.
When API content is displayed, the API terms require a visible Powered by NewTqnia link and preservation of the returned article URLs.
Why use the SDK?
- Typed, immutable response objects instead of raw arrays
- English and Arabic news, category filtering, and today/latest collections
- PSR-18 and PSR-17 interoperability with automatic client discovery
- Optional PSR-16 caching with
ETag,If-None-Match,304, andCache-Control - Optional Laravel auto-discovery, facade, configuration, and Blade component
Requirements and installation
PHP 8.2 or later and a PSR-18 implementation:
composer require newtqnia/php guzzlehttp/guzzle
Plain PHP quick start
<?php require __DIR__.'/vendor/autoload.php'; use NewTqnia\Client; $client = new Client(); $response = $client->news()->today(locale: 'en', limit: 5); foreach ($response->articles as $article) { echo $article->title.PHP_EOL; echo $article->url.PHP_EOL; }
Explicit PSR injection is also supported:
$client = new Client(httpClient: $psr18Client, requestFactory: $psr17Factory);
Laravel quick start
Laravel discovers the package automatically. Optionally publish its configuration:
php artisan vendor:publish --tag=newtqnia-config
NEWTQNIA_BASE_URL=https://api.newtqnia.com NEWTQNIA_API_KEY= NEWTQNIA_APPLICATION= NEWTQNIA_WEBSITE= NEWTQNIA_CACHE_ENABLED=true NEWTQNIA_CACHE_TTL=300
use NewTqnia\Laravel\Facades\NewTqnia; $digest = NewTqnia::news()->latest(locale: 'en', limit: 6);
The API remains available without a key. For attributed direct usage, create an optional key in your NewTqnia profile; the SDK sends it as X-API-Key when present. application and website are optional NewTqnia identification headers. RapidAPI authentication is managed by RapidAPI's gateway, not by this direct API client.
Render the required attribution with <x-newtqnia-attribution />.
The integration was verified in a temporary Laravel 12 application installed through a Composer path repository. It rendered live API data in desktop, mobile, dashboard, and Arabic RTL layouts:
| Mobile | Arabic RTL | Developer dashboard |
|---|---|---|
![]() |
![]() |
![]() |
Retrieving news
$today = $client->news()->today(locale: 'en', limit: 5); $latest = $client->news()->latest(locale: 'ar', limit: 5); $ai = $client->news()->latest(locale: 'en', limit: 10, category: 'ai'); $fluent = $client->news()->latest() ->locale('ar') ->limit(5) ->category('security') ->get();
Valid locales are en and ar; limits are 1–10. Category values are API category slugs.
Response objects
Digest exposes the documented API version, collection, optional date, timezone, locale, direction, publisher, attribution, generation time, articles, and links. Each Article exposes its ID, title, summary, category, image URL, preserved article URL, publication time, and read time. Use $digest->raw() when the original decoded response is needed.
Caching and errors
Pass any Psr\SimpleCache\CacheInterface implementation as cache:. Successful responses are cached, server max-age is honored, stale entries are revalidated with their ETag, and errors are never cached. The public API is limited to 60 requests per minute per IP.
Failures use the NewTqnia\Exception hierarchy: ValidationException, TransportException, InvalidResponseException, ApiException, RateLimitException, and ConfigurationException. See caching and error handling.
Attribution requirement
Applications displaying API content must visibly link “Powered by NewTqnia” to NewTqnia. The core helper is:
$attribution = \NewTqnia\NewTqnia::attribution();
The SDK never rewrites article URLs. Review the attribution guide and API terms.
Framework guides
Runtime dependencies
The small runtime dependency set has one job each:
psr/http-clientandpsr/http-factorydefine the interoperable HTTP transport contracts (their standard contracts bring PSR-7 messages transitively).php-http/discoveryfinds an installed PSR-18 client and PSR-17 factory for zero-configuration construction; explicit injection remains supported.psr/simple-cachepowers the implemented, optional ETag response cache.
Laravel, Guzzle, PHPUnit, PHPStan, and PHP CS Fixer are development-only. The core has no framework, logging, serializer, date, or collection dependency.
Related NewTqnia resources
- NewTqnia technology news: Read current English and Arabic technology coverage.
- Developer API documentation: Review endpoints, parameters, response formats, limits, and usage requirements.
- Embeddable technology news widget: Add responsive headlines without writing a custom integration.
- RSS and JSON technology news feeds: Subscribe to the complete feed or individual categories.
- NewTqnia Start browser extension: View concise technology coverage from a browser new-tab page.
Testing and development
composer check NEWTQNIA_LIVE_TESTS=1 vendor/bin/phpunit tests/Integration/LiveApiTest.php composer openapi:check
See CONTRIBUTING.md, SECURITY.md, and the MIT license.



