API
Prisma PHP provides a simple and user-friendly way to interact with your database.
Prisma PHP provides a simple and user-friendly way to interact with your database. With Prisma PHP, you can easily query your database, create, update, and delete records, and perform other database operations with just a few lines of code.
You can use any front-end framework or library to interact with your API. For example, you can use popular JavaScript frameworks like React, Angular, or Vue.js to build a dynamic and responsive front-end application. Additionally, you can leverage mobile app development frameworks like React Native or Flutter.
OpenAPI / Swagger
Auto-generated
If you choose to work with Swagger Docs, Prisma PHP generates an OpenAPI 3 spec out of the box from your
schema.prisma and the routes created by the generator.
The JSON lives at:
./src/app/swagger-docs/apis/pphp-swagger.json
This opens the door to any frontend that supports OpenAPI generators—TypeScript, Angular, Vue, iOS/Android, and more.
Use in React + TypeScript (Zod)
Example using openapi-zod-client:
# 1) Install generator
npm i -D openapi-zod-client
# 2) Generate client & schemas
npx openapi-zod-client \
--input http://localhost:3000/swagger-docs/apis/pphp-swagger.json \
--output ./client/src/api/pphp.ts
// client/src/features/products/useProducts.ts
import { client, schemas } from "@/api/pphp";
export async function fetchProducts()
const res = await client.GET("/products");
const parsed = schemas.Product.array().safeParse(res.data);
if (!parsed.success) throw new Error("Invalid API response");
return parsed.data;
Prefer a different stack? You can also use openapi-typescript, orval, zodios, or language-specific generators.
Useful Links for API Client Generation
- OpenAPI Zod Client (TypeScript/React)
- OpenAPI Generator (multi-language support)
To create your endpoint, follow these steps:
- Select Yes to create a backend-only project.
- Prisma PHP uses
route.phpas default routing. - Default file:
src/app/route.php - Create a folder like
products - Inside it, create
route.php - Define logic to fetch data.
- Refer to Routing documentation.
Project Structure
.your-project-name
├── .server
├── .client
│ ├── navbar
│ ├── content
│ └── footer
└── ...
CORS Configuration & Frontend Styling
CORS_ALLOWED_ORIGINS=[]
CORS_ALLOW_CREDENTIALS="true"
CORS_ALLOWED_METHODS="GET,POST,PUT,PATCH,DELETE,OPTIONS"
CORS_ALLOWED_HEADERS="Content-Type,Authorization,X-Requested-With"
CORS_EXPOSE_HEADERS=""
CORS_MAX_AGE="86400"
If you use a local frontend like Vite, add its URL to CORS_ALLOWED_ORIGINS.
Example Usage
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$products = $prisma->product->findMany();
echo json_encode($products);
Example Usage Received Data from API
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$productName = $params->productName;
$products = $prisma->product->findMany([
'where' => [
'name' => [
'contains' => $productName
]
]
]);
echo json_encode($products);
The Request::$params variable allows access to request data like GET, POST, PUT, DELETE.