- How do I install jcobhams/newsapi with Composer?
- Run composer require jcobhams/newsapi from your project root. The package has no native extensions and pulls in its HTTP dependencies automatically, so installation is a normal Composer step. Because it is a plain PHP client rather than a Laravel package, there is nothing to publish or register afterwards. In Laravel you then bind the client in one of your own service providers and pass it your NewsAPI.org key.
- Does jcobhams/newsapi support Laravel 10 and Laravel 11?
- The package is framework-agnostic, so it is not tied to a Laravel version in the way a service-provider package would be. In practice compatibility depends on the PHP and Guzzle constraints declared in its composer.json, so check those against your PHP 8.2 or 8.3 baseline before committing. Since it is MIT licensed and small, you can vendor the classes into app/Support if a constraint ever conflicts with your platform. Test the three endpoint calls inside a branch before wiring it into product code.
- How do I configure the NewsAPI.org API key in Laravel?
- The package accepts the API key when you instantiate or configure the client, so store it in an environment variable such as NEWSAPI_KEY and read it through config/news.php. Never hardcode the key or commit it, and add it to your secret manager for staging and production. Bind the configured client as a singleton in a NewsServiceProvider so the key is resolved once. Confirm the key is never written to logs by checking any request logging you have enabled.
- Which NewsAPI endpoints does jcobhams/newsapi support?
- It covers all three NewsAPI.org endpoint families: top headlines, everything search, and sources. Each is exposed through simple fluent method calls, and the package handles query parameters and response decoding for you. It does not add caching, pagination state, or scheduling on top, so those layers remain your responsibility. Run a quick spike against all three endpoints and record the raw payloads before you design your domain objects.
- Is jcobhams/newsapi still actively maintained?
- Maintenance signals are weak: the last release was in February 2023, it has a single maintainer, roughly 43 stars, and no dependent packages. That means you should assume you own the code and plan for a fork-or-vendor decision at the first sign of breakage. It is not a reason to avoid the package, but it is a reason to isolate it behind an interface you control. Budgeting a mid-term swap to hand-rolled Guzzle calls or another news provider is realistic.
- How do I handle rate limits and NewsAPI errors with this package?
- The client does not give you caching or rate limiting out of the box, so add Laravel's rate limiter and a read-through cache with a per-query TTL in front of it. Catch whatever exceptions the client throws and translate them into your own domain exception types so callers never depend on the package. Verify whether NewsAPI's structured error payload and rate-limit headers are surfaced or reduced to generic exceptions during your spike. Also add retry and backoff around queued fetch jobs rather than retrying inside the request cycle.
- Should I wrap jcobhams/newsapi in my own service class in Laravel?
- Yes. Define a NewsProvider interface in your domain and implement it with a NewsApiProvider adapter that internally calls this package. Bind the adapter in a service provider and inject the interface into controllers and jobs so nothing in your application core references the package directly. That keeps the client a replaceable transport detail and makes swapping to GNews, Mediastack, or raw Guzzle calls a one-class change. It also gives you a single place to add caching, logging, and error translation.
- How do I test Laravel code that uses jcobhams/newsapi?
- Mock at the boundary you own: fake your NewsProvider interface in application tests, and use recorded NewsAPI fixtures in contract tests for the adapter. If you need to test the adapter itself, mock the underlying HTTP layer with Guzzle's mock handler or Laravel's HTTP fakes, never the live API. Check whether the package ships a test suite and whether it mocks HTTP or hits the network before you rely on it. Fixture-based contract tests are also what makes a future provider swap safe.
- Is NewsAPI.org usable in production on the free tier?
- No. The NewsAPI.org free tier is development-only, with rate caps and delayed results, so production use requires a paid commercial plan at a materially higher price point. The package cannot insulate you from that commercial dependency, which is the dominant vendor risk here. Review the licence terms for storing, displaying, and redistributing article content, including attribution requirements, before launch. Confirm the cost and terms as part of your spike rather than after the feature ships.
- What are alternatives to jcobhams/newsapi for Laravel?
- GNews, Mediastack, and NewsCatcher are common alternatives, and hand-rolled Guzzle calls against NewsAPI.org directly are entirely viable given how thin this client is. The right move is to pick the provider behind your own NewsProvider interface so the choice is reversible. Evaluate alternatives on pricing, rate limits, content licensing, and PHP 8.2 plus Laravel 10 and 11 compatibility rather than on stars alone. Keep the adapter small so switching providers stays a contained change.