Download the PHP package coagus/php-api-builder without Composer

On this page you can find all versions of the php package coagus/php-api-builder. 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 php-api-builder

Latest Stable Version Total Downloads License Tests PHP 8.4+ Docker

PHP API Builder v2

Build RESTful APIs in PHP in minutes. Define your entities, get CRUD automatically, and focus on your business logic.

That's it. You now have a fully functional API with GET, POST, PUT, PATCH, DELETE endpoints, pagination, filtering, sorting, validation, soft deletes, and relationships. No controllers, no routes to configure, no boilerplate.

Features

Quick Start

With PHP installed

  1. Create a new project:

  2. Initialize and start:

Without PHP (Docker only)

  1. Create your project directory:

  2. Initialize the project:

  3. Start the services:

  4. Verify it works:

Running CLI commands without PHP: Once docker compose up -d is running, enter the container and use the CLI from there:

Alternatively, the ./api wrapper auto-detects Docker and works without entering the container.

Try the Demo

Explore all library features with a ready-made Blog API demo:

  1. Install the demo (after init + docker compose up):

  2. Open Swagger UI at http://localhost:8080/api/v1/docs/swagger

  3. When done exploring, clean up:

The demo creates a complete Blog API with Users, Posts, Comments, and Tags -- showcasing entities, services, relationships, JWT auth, validation, rate limiting, middleware, and OpenAPI documentation.

Create Your First Entity

This generates entities/User.php:

Your endpoints are ready:

Services (No Database)

Not everything needs a database. Services handle external APIs, health checks, custom logic:

Well-known routes (RFC 8615)

Not every URL belongs under /api/v1. RFC 8615 reserves the /.well-known/* namespace for host-level metadata: OpenID Connect discovery, OAuth 2.0 authorization-server metadata, JWKS, security.txt, and similar. Register these paths with the optional third constructor argument:

The dispatcher consults the wellKnown map before the apiPrefix router, so these paths resolve regardless of the prefix value. Each handler is a regular Service (extends Coagus\PhpApiBuilder\Resource\Service) — its get() method writes a response with $this->success(...) exactly like any other service.

Malformed entries fail fast at construction time. If the class does not exist, the method is not callable on an instance of that class, or the tuple is not [Class::class, 'method'], the API constructor throws InvalidArgumentException before any request is served.

A few notes:

Hybrid Resources (CRUD + Custom Endpoints)

Combine automatic CRUD with custom business logic:

Per-route Middleware

Attach middleware to a specific resource class or HTTP method with the #[Middleware] attribute. Parameters are forwarded to the middleware constructor as named arguments, and the attribute is repeatable:

The dispatch pipeline runs global middleware first (registered via API::middleware([...])), then class-level #[Middleware], then method-level #[Middleware], then the handler. The middleware class must implement MiddlewareInterface; otherwise dispatch fails loudly.

Virtual Property Hooks with #[Ignore]

#[Ignore] marks a public property as invisible to the ORM, validator, and OpenAPI generator. It pairs naturally with a PHP 8.4 set-only hook that writes to a sibling backing column:

An #[Ignore] property is not written to INSERT/UPDATE, not hydrated from SELECT rows, not checked by the validator, not emitted in response bodies, and not surfaced in OpenAPI schemas. Use it whenever the property exists only to transform input — never as a persisted column.

Query Builder

Five levels of complexity -- use what you need:

Validation via Attributes

#[Required] validates presence, #[Email] validates format, #[Unique] checks the database, #[Hidden] excludes the field from responses, #[Ignore] hides a virtual property from ORM/validator/schemas, and property hooks sanitize on assignment.

Auto-Generated API Documentation

Your entity attributes generate OpenAPI 3.1 specs automatically:

No extra annotations needed. #[Required] becomes required, #[MaxLength(50)] becomes maxLength: 50, #[Hidden] fields are excluded from response schemas.

CLI Commands

The ./api wrapper detects whether to use local PHP or Docker automatically. Teams with mixed setups work seamlessly.

Database Support

Configure in .env:

The ORM generates driver-specific SQL through PDO. Switch databases by changing one line.

Connection URIs (Supabase, RDS, Heroku, Render, …)

Managed Postgres and MySQL hosts publish credentials as a single URI. Pass it directly to Connection::configure() under the dsn key and the library expands it into the individual fields:

Supported schemes: postgresql://, postgres://, mysql://, mariadb://. URL-decoded credentials, default ports (5432 / 3306), and query-string options (e.g. ?sslmode=require) are dropped — libpq and the MySQL driver negotiate TLS automatically against any TLS-enforcing server. Caller-provided fields override URI-parsed ones, so ['dsn' => '...', 'database' => 'override'] wins.

Security

Built-in by default, following OWASP recommendations:

Project Structure

Requirements

Installation

Documentation

Full architecture and design documentation is available in resources/docs/diagrams/.

AI Development Skill

The library includes an AI skill that teaches Claude Code and Cowork how to work with php-api-builder. It is installed automatically by ./api init into .claude/skills/php-api-builder/, so your AI assistant can generate entities, services, queries, and configurations following the library's patterns.

License

MIT License. See LICENSE for details.

Author

Christian Agustin - [email protected]


All versions of php-api-builder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
firebase/php-jwt Version ^7.0
monolog/monolog Version ^3.5
vlucas/phpdotenv Version ^5.6
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 coagus/php-api-builder contains the following files

Loading the files please wait ...