Skip to the endpoints
CI Bridge v1

CodeIgniter 3 · CodeIgniter 4

Your CodeIgniter app, wired to one JSON endpoint

A key, five routes and a client class for each framework version. CI3 posts through cURL, CI4 through the CURLRequest service, and both land in the same table you can watch live.

Endpoints
5
Auth
1 header
Composer
none
PHP
5.6+
bash — push a lead
curl -X POST https://your-app-url/api/v1/records \
  -H "Content-Type: application/json" \
  -H "X-API-Key: ci_live_7f3b2a9c41d84e6fb05c7d31" \
  -d '{"name":"Nikhil Bhatt","email":"[email protected]","source":"ci4","reference":"LEAD-4821"}'

HTTP/1.1 201 Created
{
  "ok": true,
  "id": 12,
  "record": {
    "id": 12,
    "name": "Nikhil Bhatt",
    "email": "[email protected]",
    "source": "ci4",
    "reference": "LEAD-4821",
    "created_at": "2026-12-05T09:41:08.512Z"
  }
}

The whole API fits on one screen

Every route answers JSON and expects X-API-Key. Base path /api/v1 on this app's own domain.

MethodPathWhat it doesFields
GET /api/v1/ping Handshake — confirms the key works before you ship —
GET /api/v1/records Pull records back into your CI app ?limit=25
POST /api/v1/records Push a lead, order or form submission name, email, source, reference, payload
GET /api/v1/records/:id Read one record by id —
DELETE /api/v1/records/:id Remove a record after your CI job consumed it —

Two versions, two clients, same payload

Paste these in as they are. Only the base URL and the key change between projects.

CodeIgniter 3.1.x application/libraries

The cURL library

<?php defined('BASEPATH') OR exit('No direct script access allowed');
// application/libraries/Ci_bridge.php

class Ci_bridge {

    private $base;
    private $key;

    public function __construct()
    {
        $CI =& get_instance();
        $CI->config->load('ci_bridge', TRUE);
        $this->base = $CI->config->item('base_url', 'ci_bridge');
        $this->key  = $CI->config->item('api_key',  'ci_bridge');
    }

    public function call($path, $data = NULL, $method = 'GET')
    {
        $ch = curl_init($this->base . $path);
        curl_setopt_array($ch, array(
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_CUSTOMREQUEST  => $method,
            CURLOPT_HTTPHEADER     => array(
                'Content-Type: application/json',
                'Accept: application/json',
                'X-API-Key: ' . $this->key,
            ),
            CURLOPT_POSTFIELDS     => is_null($data) ? NULL : json_encode($data),
            CURLOPT_TIMEOUT        => 15,
        ));

        $body   = curl_exec($ch);
        $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $error  = curl_error($ch);
        curl_close($ch);

        return array(
            'status' => $status,
            'data'   => json_decode($body, TRUE),
            'error'  => $error,
        );
    }
}

Config + controller

<?php
// application/config/ci_bridge.php
$config['base_url'] = 'https://your-app-url/api/v1';
$config['api_key']  = 'ci_live_7f3b2a9c41d84e6fb05c7d31';

// application/controllers/Leads.php
class Leads extends CI_Controller {

    public function store()
    {
        $this->load->library('ci_bridge');

        $res = $this->ci_bridge->call('/records', array(
            'name'      => $this->input->post('name', TRUE),
            'email'     => $this->input->post('email', TRUE),
            'source'    => 'ci3',
            'reference' => 'LEAD-' . time(),
            'payload'   => array('plan' => $this->input->post('plan', TRUE)),
        ), 'POST');

        if ($res['status'] === 201) {
            $this->session->set_flashdata('ok', 'Synced as #' . $res['data']['id']);
            redirect('leads');
        }

        log_message('error', 'Bridge failed: ' . $res['status']);
        show_error('Could not reach the bridge', 502);
    }
}
CodeIgniter 4.5.x app/Config, app/Controllers

Config class + .env

<?php
// app/Config/Bridge.php
namespace Config;

use CodeIgniter\Config\BaseConfig;

class Bridge extends BaseConfig
{
    public string $baseUrl = 'https://your-app-url/api/v1';
    public string $apiKey  = 'ci_live_7f3b2a9c41d84e6fb05c7d31';
}

# .env  (overrides the class above, nothing committed)
bridge.baseUrl = 'https://your-app-url/api/v1'
bridge.apiKey  = 'ci_live_7f3b2a9c41d84e6fb05c7d31'

CURLRequest controller

<?php
// app/Controllers/Leads.php
namespace App\Controllers;

use Config\Services;

class Leads extends BaseController
{
    public function store()
    {
        $cfg    = config('Bridge');
        $client = Services::curlrequest([
            'baseURI'     => rtrim($cfg->baseUrl, '/') . '/',
            'timeout'     => 15,
            'http_errors' => false,
        ]);

        $res = $client->post('records', [
            'headers' => [
                'X-API-Key' => $cfg->apiKey,
                'Accept'    => 'application/json',
            ],
            'json' => [
                'name'      => $this->request->getPost('name'),
                'email'     => $this->request->getPost('email'),
                'source'    => 'ci4',
                'reference' => 'LEAD-' . time(),
                'payload'   => ['plan' => $this->request->getPost('plan')],
            ],
        ]);

        $body = json_decode($res->getBody(), true);

        if ($res->getStatusCode() === 201) {
            return redirect()->to('/leads')->with('ok', 'Synced as #' . $body['id']);
        }

        log_message('error', 'Bridge said {0}', [$res->getStatusCode()]);
        return redirect()->back()->with('error', $body['error'] ?? 'Bridge unreachable');
    }

    public function pull()
    {
        $cfg    = config('Bridge');
        $client = Services::curlrequest(['baseURI' => rtrim($cfg->baseUrl, '/') . '/']);

        $res = $client->get('records?limit=25', [
            'headers' => ['X-API-Key' => $cfg->apiKey],
        ]);

        return $this->response->setJSON(json_decode($res->getBody(), true));
    }
}

Connected in three steps

01

Copy your API key

The console holds one live key. Paste it into application/config/ci_bridge.php (CI3) or .env as bridge.apiKey (CI4).

02

Drop in the client

CI3 gets a 40-line library using cURL. CI4 uses the built-in CURLRequest service — no Composer package, no vendor lock.

03

Watch it land

Every call is written to the request log with method, status and which framework sent it, so a 401 is obvious in seconds.

A developer reviewing PHP code on a dark terminal screen

Built for the legacy app you cannot rewrite

Most CodeIgniter 3 projects still in production cannot take a modern SDK — no Composer autoload, PHP 5.6, a shared host with open_basedir. The bridge asks for nothing but cURL.

Header auth, nothing clever

X-API-Key on every request, or ?api_key= when a legacy CI3 host strips custom headers.

JSON and form-encoded

Post application/json or plain POST fields — the endpoint reads both, so CI3's $this->input works untouched.

A log you can trust

Status codes, timestamps and the source flag you send, kept for the last 200 calls.

Predictable errors

401 for a bad key, 422 for a missing name, 404 for an unknown id. Never an HTML error page in your JSON parser.

Send your first request in the next five minutes

The console shows your live key, a tester that writes a real record, and the request log your CodeIgniter calls appear in.

Open the console