PHPackages                             ctechhindi/codeigniter-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. ctechhindi/codeigniter-api

ActiveProject[API Development](/categories/api)

ctechhindi/codeigniter-api
==========================

CodeIgniter API Controller

681.1k47[2 issues](https://github.com/jeevan15498/CodeIgniter-API-Controller/issues)[1 PRs](https://github.com/jeevan15498/CodeIgniter-API-Controller/pulls)PHP

Since Dec 8Pushed 6y ago13 watchersCompare

[ Source](https://github.com/jeevan15498/CodeIgniter-API-Controller)[ Packagist](https://packagist.org/packages/ctechhindi/codeigniter-api)[ RSS](/packages/ctechhindi-codeigniter-api/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (8)DependenciesVersions (1)Used By (0)

CodeIgniter API Controller v.1.1.7
==================================

[](#codeigniter-api-controller-v117)

This extension is powered by `Jeevan Lal`.

Files
-----

[](#files)

[API Documentation](https://github.com/jeevan15498/CodeIgniter-API-Controller#documentation)

- `\application\libraries\API_Controller.php`
- `\application\helpers\api_helper.php`
- `\application\config\api.php`

[Token Documentation](token.md)

- `\application\libraries\Authorization_Token.php`
- `\application\config\jwt.php`
- [PHP-JWT](https://github.com/firebase/php-jwt) Library `\application\third_party\php-jwt\`

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

[](#installation)

You can install this project into your PC using composer.

The recommended way to install composer packages is:

```
composer require ctechhindi/codeigniter-api:dev-master --prefer-source

```

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

[](#requirements)

1. PHP 5.4 or greater
2. CodeIgniter 3.0+

Note: The library is used in CodeIgniter v3.8 and PHP 5.6.8.

DEMO
----

[](#demo)

>

Simple API

```
header("Access-Control-Allow-Origin: *");

// API Configuration
$this->_apiConfig([
    /**
     * By Default Request Method `GET`
     */
    'methods' => ['POST'], // 'GET', 'OPTIONS'

    /**
     * Number limit, type limit, time limit (last minute)
     */
    'limit' => [5, 'ip', 'everyday'],

    /**
     * type :: ['header', 'get', 'post']
     * key  :: ['table : Check Key in Database', 'key']
     */
    'key' => ['POST', 'string_key' ], // type, {key}|table (by default)
]);

// return data
$this->api_return(
    [
        'status' => true,
        "result" => "Return API Response",
    ],
200);
```

Documentation
-------------

[](#documentation)

### Setup API Request Methods

[](#setup-api-request-methods)

- This Function by default request method `GET`

```
$this->_APIConfig();
```

- Set `API Request` Method `POST, GET, ..`

```
$this->_APIConfig([
    'methods' => ['POST', 'GET'],
]);
```

---

### Use API Limit

[](#use-api-limit)

Before using the limit in API, we need to load the codeigniter `database library`. You can also load the database library in the autoload config `config/autoload.php` file.

After database library loaded, database must be set in database config file `config/database.php`.

After creating and setting up a database, we need to create a table for API Limit `[api_limit]` in the database. like this.

```
CREATE TABLE `api_limit` (
    `id` INT NOT NULL AUTO_INCREMENT ,
    `user_id` INT NULL DEFAULT NULL ,
    `uri` VARCHAR(200) NOT NULL ,
    `class` VARCHAR(200) NOT NULL ,
    `method` VARCHAR(200) NOT NULL ,
    `ip_address` VARCHAR(50) NOT NULL ,
    `time` TEXT NOT NULL ,    PRIMARY KEY  (`id`)
) ENGINE = InnoDB;
```

The name of the database table of api limit is `api_limit` by default. Which we can change through the API configuration file `[config/api.php]`. like this.

```
/**
 * API Limit database table name
 */
$config['api_limit_table_name'] = 'api_limit';

/**
 * Set API Timezone
 */
$config['api_timezone'] = 'Asia/Kolkata';
```

Now we can use API Limit Method.

Thus this API can be run only 10 times in 5 minutes. It on `IP address`.

```
/**
 * API Limit
 * ----------------------------------
 * @param: {int} API limit Number
 * @param: {string} API limit Type (IP)
 * @param: {int} API limit Time [minute]
 */

$this->_APIConfig([
    // number limit, type limit, time limit (last minute)
    'limit' => [10, 'ip', 5]
]);
```

At API limit `time argument` we can also use `everyday` which will follow the api limit per day. On the same API address

```
/**
 * API Limit
 * ----------------------------------
 * @param: {int} API limit Number
 * @param: {string} API limit Type (IP)
 * @param: {string} API limit [everyday]
 */

$this->_APIConfig([
    // number limit, type limit, everyday
    'limit' => [10, 'ip', 'everyday']
]);
```

---

### Use API Key without Database

[](#use-api-key-without-database)

We can set the API key in the Request Header. by default, the name of the header is `X-API-K`, which we can change in the API config file `[config/api.php]`. like this

```
/**
 * API Key Header Name
 */
$config['api_key_header_name'] = 'X-API-KEY';
```

Use this code in your API Controller file.

```
/**
 * Use API Key without Database
 * ---------------------------------------------------------
 * @param: {string} Types
 * @param: {string} API Key
 */

$this->_APIConfig([
    'key' => ['header', 'Set API Key'],
]);
```

---

### Use API Key with Database

[](#use-api-key-with-database)

We can also check the API key by `databases`. For this, we need to first create `api_keys` table in MySQL. like this

```
CREATE TABLE `api_keys` (
    `id` INT NOT NULL AUTO_INCREMENT ,
    `api_key` VARCHAR(50) NOT NULL ,
    `controller` VARCHAR(50) NOT NULL ,
    `date_created` DATE NULL DEFAULT NULL ,
    `date_modified` DATE NULL DEFAULT NULL ,    PRIMARY KEY  (`id`)
) ENGINE = InnoDB;
```

The name of the database table of API Keys is `api_keys` by default. Which we can change through the API configuration file `[config/api.php]`. like this.

```
/**
 * API Keys Database Table Name
 */
$config['api_keys_table_name'] = 'api_keys';
```

Set API keys in `api_keys` database table And Use this code in your API Controller file.

```
/**
 * API Key
 * ---------------------------------------------------------
 * @param: {string} Types
 * @param: {string} [table]
 */
$this->_APIConfig([
    // 'key' => ['header', 'table'],
    'key' => ['header'],
]);
```

---

### Use Custom Function in API Key

[](#use-custom-function-in-api-key)

```
/**
 * API Key
 * ---------------------------------------------------------
 * @param: {string} Types
 * @param: [function] return api key
 */
$this->_APIConfig([
    'key' => ['header', $this->key() ],
]);

// This is Custom function and return api key
private function key() {
    return 1452;
}
```

---

### Add Custom Data in API Responses

[](#add-custom-data-in-api-responses)

In response to the API, we can also add custom data to something like this.

```
$this->_APIConfig([
    'key' => ['header'],
    'data' => [ 'is_login' => false ] // custom data
]);
```

API Output ::

```
{
    "status": false,
    "error": "API Key Header Required",
    "is_login": false
}
```

---

### API Return Data

[](#api-return-data)

This method is used to return data to api in which the response data is `first` and the `second` request status code.

```
/**
 * Return API Response
 * ---------------------------------------------------------
 * @param: API Data
 * @param: Request Status Code
 */
$this->api_return(data, status_code);
```

#### Request Status Code List

[](#request-status-code-list)

Status CodeStatus Text200OK401UNAUTHORIZED404NOT FOUND408Request Timeout400BAD REQUEST405Method Not AllowedUsing the Config file in the API key
------------------------------------

[](#using-the-config-file-in-the-api-key)

1. Create config file `\application\config\api_keys.php`
2. Use in API Controller like this

```
// load API Keys config file
$this->load->config('api_keys');

$this->_APIConfig([
    'key' => ['post', $this->config->item('controller/api key name')],
]);
```

Reporting Issues
----------------

[](#reporting-issues)

If you have a problem with this plugin or found any bug, please open an issue on [GitHub](https://github.com/jeevan15498/CodeIgniter-API-Controller/issues).

License
=======

[](#license)

CodeIgniter API Controller is licensed under [MIT](http://www.opensource.org/licenses/MIT)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 91.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2736c51cde4556bbdee4950ccadc7a81c6c97c9998e3faebff9f1f2b97103a65?d=identicon)[ctechhindi](/maintainers/ctechhindi)

---

Top Contributors

[![jeevan15498](https://avatars.githubusercontent.com/u/40597858?v=4)](https://github.com/jeevan15498 "jeevan15498 (11 commits)")[![jeevan-lal](https://avatars.githubusercontent.com/u/40091315?v=4)](https://github.com/jeevan-lal "jeevan-lal (1 commits)")

---

Tags

apicodeignitercodeigniter-libraryphpphp-jwtrestrest-api

### Embed Badge

![Health badge](/badges/ctechhindi-codeigniter-api/health.svg)

```
[![Health](https://phpackages.com/badges/ctechhindi-codeigniter-api/health.svg)](https://phpackages.com/packages/ctechhindi-codeigniter-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)[facebook/php-business-sdk

PHP SDK for Facebook Business

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

PHP wrapper for the Meilisearch API

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

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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