Download the PHP package jivtesh/ci4-api-generator without Composer

On this page you can find all versions of the php package jivtesh/ci4-api-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ci4-api-generator

CodeIgniter 4 API Generator

PHP Version CodeIgniter

Automatically generate RESTful APIs for your CodeIgniter 4 application based on your MySQL database tables. No code required! Just install, configure your database, and your APIs are ready to use.

✨ Features

📋 Requirements

🚀 Installation

Install via Composer:

That's it! The package uses CodeIgniter's auto-discovery feature. Your APIs are now live at http://yoursite.com/api/v1/.

🎯 Quick Start

1. Install the Package

2. Configure Database

Make sure your database is configured in app/Config/Database.php:

3. Test Your APIs

Your APIs are now available! If you have a table named users, you can access:

4. View Available Routes

5. Generate API Documentation

This generates the file openapi.json in writable-->api-docs folderm which is used by Scalar in View file to create api documentation.

Then visit http://yoursite.com/api/v1/docs to see your interactive API documentation.

📚 Available Endpoints

For each table in your database, the following endpoints are automatically created:

Method Endpoint Description Example
GET /api/v1/{table} List all records (paginated) /api/v1/users
GET /api/v1/{table}/{id} Get a single record /api/v1/users/1
GET /api/v1/{table}/{id1}/{id2} Get a single record (composite key) /api/v1/payments/103/HQ336336
POST /api/v1/{table} Create a new record /api/v1/users
PUT /api/v1/{table}/{id} Update a record /api/v1/users/1
PUT /api/v1/{table}/{id1}/{id2} Update a record (composite key) /api/v1/payments/103/HQ336336
DELETE /api/v1/{table}/{id} Delete a record /api/v1/users/1
DELETE /api/v1/{table}/{id1}/{id2} Delete a record (composite key) /api/v1/payments/103/HQ336336

Notes:

🔧 Configuration (Optional)

By default, the package works with zero configuration. However, you can customize behavior by creating a config file.

Create Custom Configuration

  1. Create app/Config/ApiGenerator.php:

Configuration Options

Basic Settings

Table Selection

Enable/Disable Endpoints Per Table

Restrict Visible Columns

Custom Validation Rules

Multi-Tenant Filtering

Dynamic Multi-Tenant Example:

Pagination Settings

Complete Configuration Example

🎨 API Usage Examples

Listing Records (GET)

Response:

Get Single Record (GET)

Single Primary Key

Response:

Composite Primary Key

For tables with composite primary keys (e.g., payments table with customerNumber and checkNumber):

Response:

Note: The order of primary key values in the URL must match the order defined in the database schema.

Create Record (POST)

Response:

Update Record (PUT)

Single Primary Key

Response:

Composite Primary Key

Response:

Delete Record (DELETE)

Single Primary Key

Response:

Composite Primary Key

Response:

🖥️ CLI Commands

List All Available APIs

Output:

List APIs for Specific Table

Generate API Documentation

Refresh Everything

📖 API Documentation

The package includes beautiful, interactive API documentation powered by Scalar.

Accessing Documentation

  1. Generate the OpenAPI specification:

  2. Visit the documentation URL:

Features of Documentation

Customizing Documentation Path

Disabling Documentation

🔒 Security & Best Practices

Authentication & Authorization

This package provides the API infrastructure. You should add authentication:

  1. Create an Authentication Filter (app/Filters/ApiAuthFilter.php):

  2. Register Filter in app/Config/Filters.php:

Recommended Security Practices

  1. Always use HTTPS in production
  2. Implement rate limiting (use CodeIgniter's Throttle filter)
  3. Validate and sanitize all inputs (auto-handled by validation rules)
  4. Use strong validation rules for sensitive fields
  5. Hide sensitive columns using enabledColumnsToShow
  6. Restrict endpoints as needed via enabledEndpoints
  7. Implement proper CORS policies if accessed from browsers
  8. Use multi-tenant filtering for data isolation

🛠️ Advanced Usage

Dynamic Configuration

You can modify configuration at runtime:

Custom Validation Logic

Extend the ApiController for complex validation:

Soft Deletes Support

The package automatically detects deleted_at columns and enables soft deletes.

Timestamp Handling

Automatically detects and handles created_at and updated_at columns.

🐛 Troubleshooting

APIs Not Working

  1. Check if composer autoload is updated:

  2. Verify database connection:

  3. Check routes are registered:

  4. Clear cache:

404 Errors

  1. Ensure mod_rewrite is enabled (Apache)
  2. Check .htaccess file exists in public folder
  3. Verify $baseURL in app/Config/App.php

Validation Errors

Performance Issues

📊 Response Formats

Success Response

Error Responses

HTTP Status Codes

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📝 License

This package is open-sourced software licensed under the BSD-3-Clause license.

👤 Author

Jivtesh Ghatora

🙏 Acknowledgments


Star ⭐ this repository if you find it helpful!


All versions of ci4-api-generator with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
codeigniter4/framework Version ^4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jivtesh/ci4-api-generator contains the following files

Loading the files please wait ...