PHPackages                             alisajjad/php7\_api - 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. alisajjad/php7\_api

ActiveProject[API Development](/categories/api)

alisajjad/php7\_api
===================

A PHP basic starter for single url API development. It provides the basic functionalities with different authorization handles as well as Mysqli Wrapper.

1.1.0(5y ago)0131MITPHPPHP &gt;=7.2.0CI failing

Since Mar 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/alisajjad96/php7_api)[ Packagist](https://packagist.org/packages/alisajjad/php7_api)[ RSS](/packages/alisajjad-php7-api/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

php7\_api
=========

[](#php7_api)

A PHP basic starter for single url API development. It provides the basic functionalities with different authorization handles as well as Mysqli Wrapper.

Requirements
------------

[](#requirements)

- PHP 7.2 or higher with mysqli extension

Installation
------------

[](#installation)

```
composer require alisajjad/php7_api

```

File Structure
--------------

[](#file-structure)

- app: Contains core app files
- components: Contains your custom controllers
- connection: Mysqli Wrapper &amp; result storage objects
- includes: Contains common functions, traits, interfaces
- tests: Test cases
- configs.php: App configurations
- routes.php: All app routes

Configurations
--------------

[](#configurations)

All the configurations can be modified/added through configs.php

- Database
    - host
    - user
    - password
    - db
    - port
    - socket
- Environment
    - debug: true on production, false on development
    - url: url of production/development server
- Authorization
    - None: No Authorization
    - Basic: Authorization with username &amp; password
    - Bearer: Authorization with token
    - Digest: Authorization with encrypted username &amp; password
    - Header: Custom header authorization

Usage
-----

[](#usage)

After installing add your routes in `routes.php`

```
[
    'welcome' => [
        'class' => \PHP7API\Components\Welcome::class,
        'method' => 'welcome'
    ],
    'welcome_args' => [
        'class' => \PHP7API\Components\Welcome::class,
        'method' => 'welcomeArgs',
        'requires' => [
            'param_1',
            'param_2',
        ]
    ],
]

```

Where welcome is route name and class, method is the what the app will call. The requires makes the given parameters required in current route inputs.

A Basic Component:

```
namespace PHP7API\Components;

class Welcome extends Component{

    public function welcome($request, $route){

        return [
            'success' => 1,
            'message' => 'success'
        ];
    }
}

```

Which outputs the response:

```
{"success":1,"message":"success","time":"2020-03-26 21:23:18"}

```

The "`$request`" parameter contains all the given input

The "`$route`" parameter contains current Route information.

### Call Api

[](#call-api)

Using Curl

```
$ch = curl_init();

$curlData = http_build_query([
    'route' => 'welcome_args',
    'param_1' => 'value_1',
    'param_2' => 'value_2',
]);

$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer your_token'
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);

$response = json_decode($server_output, true);

```

### Mysqli Usage

[](#mysqli-usage)

Initiate the object:

```
$db = MySql::instance();

```

or

```
$db = MySql::init();

```

`MySql::instance()` uses the db configurations from `configs.php`

`MySql::init()` uses the given configurations from arguments or `configs.php` if no argument is given.

Execute Query:

```
$result = $db->exec($sql);

```

`$result` is true on success, false on query failure.

Execute Fetch Query:

```
$result = $db->fetch($sql);

```

`$result` is MysqlResultCollection object on success, null on query failure.

#### MysqlResultCollection

[](#mysqlresultcollection)

All the query results will be stored in this object.

Common Methods:

- getAll() - returns all rows in array
- getRowsNum() - returns rows count
- isEmpty() - checks if result is empty
- first() - Returns first row
- last() - Returns last row
- nth() - Returns nth index of row

The first row can be directly accessed simply by:

```
$result->first_row_column;

```

or

```
$result->first()->first_row_column;

```

Using Loop:

```
foreach ($user as $name => $value):
    echo $value->column;
endforeach;

```

Limitation
----------

[](#limitation)

- This app only uses one url for all the routes
- Only has MySQLi Wrapper yet.
- Doesn't support OAuth1 &amp; OAuth2 yet.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~72 days

Total

3

Last Release

2099d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bae932c7660fb4c40864626c67cba317708c67addf6c54619ba7846cd1a205ae?d=identicon)[Ali Sajjad](/maintainers/Ali%20Sajjad)

---

Top Contributors

[![alisajjad96](https://avatars.githubusercontent.com/u/13929968?v=4)](https://github.com/alisajjad96 "alisajjad96 (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alisajjad-php7-api/health.svg)

```
[![Health](https://phpackages.com/badges/alisajjad-php7-api/health.svg)](https://phpackages.com/packages/alisajjad-php7-api)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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