PHPackages                             gfargo/newsapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. gfargo/newsapi

ActiveLibrary[API Development](/categories/api)

gfargo/newsapi
==============

PHP API wrapper for NewsAPI.org

0.2.0(7y ago)035↓100%[1 issues](https://github.com/GFargo/newsapi/issues)[4 PRs](https://github.com/GFargo/newsapi/pulls)MITPHPPHP &gt;=7.1

Since Jan 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/GFargo/newsapi)[ Packagist](https://packagist.org/packages/gfargo/newsapi)[ RSS](/packages/gfargo-newsapi/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (7)Used By (0)

[![](https://camo.githubusercontent.com/1f5e903db2965e6af86ac8c2ccb2163108d0fcc34f208f8df26dc8090dcf4503/68747470733a2f2f692e696d6775722e636f6d2f68553367454e622e706e67 "NewsAPI")](https://camo.githubusercontent.com/1f5e903db2965e6af86ac8c2ccb2163108d0fcc34f208f8df26dc8090dcf4503/68747470733a2f2f692e696d6775722e636f6d2f68553367454e622e706e67)🗞 PHP wrapper for [NewsAPI.org](https://newsapi.org)

[![travis-build](https://camo.githubusercontent.com/425afca21e63665a83820d63a24b489b747b39be1efa1a5e1e13a9d240fc72ac/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f47466172676f2f6e6577736170692e7376673f7374796c653d666c6174266c6f676f3d747261766973)](https://travis-ci.org/GFargo/newsapi)[![codecov](https://camo.githubusercontent.com/cfd54962c496e2090a0a832a14a5cf4b6c8bb3ecdb343f4b1d6bdcc23518de78/68747470733a2f2f636f6465636f762e696f2f67682f47466172676f2f6e6577736170692f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/GFargo/newsapi)[![Codacy Badge](https://camo.githubusercontent.com/4381252775e9679241d24d0eee468bc130045e30d24fec5b4c26a165efcafb3b/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3666346162313331373330363434653562623634616265663836633735633038)](https://www.codacy.com/app/GFargo/newsapi?utm_source=github.com&utm_medium=referral&utm_content=GFargo/newsapi&utm_campaign=Badge_Grade)

Getting Started
---------------

[](#getting-started)

Implementing the NewsAPI within your PHP application has never been smoother. The principle behind its design is simplicity without forfeiting power or flexibility.

### Installation

[](#installation)

Add it to your project via Composer.

```
composer require gfargo/newsapi
```

### Dependencies

[](#dependencies)

This wrapper utilizes the [Requests](https://github.com/rmccue/requests) library from Ryan McCue.

> Official website &amp; documentation can be found [here](http://requests.ryanmccue.info/).

### Configuration

[](#configuration)

Once included in your project, setup should be very straightforward. Only requirement is a valid API key provided by [NewsAPI.org](NewsAPI.org/account/).

Usage
-----

[](#usage)

### Step 1. Set Access Token

[](#step-1-set-access-token)

```
\NewsAPI\Client::setAccessToken('276537c6a3824cdd9eae393c024ff732');
```

### Step 2. Setup Query

[](#step-2-setup-query)

Making requests to the API is done via `query` method, which accepts three parameters. Below are a few examples.

**`Query` parameters:**

- `(string) $endpoint` Target endpoint. Options are `top`, `everything`, and `sources`.
- `(array) $query_params` Query parameters passed to NewsAPI.org
- `(array) $request_options` Options passed to Requests library to control CURL.

**Examples:**

```
// All articles featuring the keyword 'Open Source'
$request = NewsAPI\Client::query( 'everything', [ 'q' => 'Open Source' ] );
```

```
// Top headlines for articles featuring the keyword 'Technology'
$request = NewsAPI\Client::query( 'top', [ 'q' => 'Technology' ] );
```

```
// Top articles from 'Business' category
$request = NewsAPI\Client::query( 'top', [ 'category' => 'business' ] );
```

### Step 3. Handling Responses

[](#step-3-handling-responses)

Each query returns a `Request_Response` object, more on this [here](http://requests.ryanmccue.info/api/class-Requests_Response.html).

In short the `Requests` library makes dealing with the API responses much easier.

```
$request = NewsAPI\Client::query( 'top', [ 'category' => 'business' ] );

$request->status_code             // int(200)
$request->headers['content-type'] // string(31) "application/json; charset=utf-8"
$request->url                     // string(54) "https://newsapi.org/v2/top-headlines?category=business"
$request->body                    // string(14385) "{...}"
```

Change log
----------

[](#change-log)

> [Automated release notes can be found here →](https://github.com/gfargo/newsapi/releases)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2662d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a2063d69cf3368c62ea62630ef06aa9733f0fefcb5af5d70a8cc20690ad51d4?d=identicon)[GFargo](/maintainers/GFargo)

---

Tags

phpapiwrapper newsnewsapi

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gfargo-newsapi/health.svg)

```
[![Health](https://phpackages.com/badges/gfargo-newsapi/health.svg)](https://phpackages.com/packages/gfargo-newsapi)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
