php-typescript-api
TypeScript icon, indicating that this package has built-in type declarations

2.6.13 • Public • Published

php-typescript-api

Build a typed Web API using PHP and TypeScript

Disclaimer: This is not an officially supported Google product

This project:

  • helps with data validation on the server side by providing fields or phpstan to define allowed request/response types.
  • generates a typed API client in TypeScript.
  • consists of a server (PHP) library, a client (TypeScript) library, and an example of its usage.

Usage

Server side (PHP)

  • Install php-typescript-api using composer:

    composer require allestuetsmerweh/php-typescript-api

  • Implement some endpoints for your API (examples).

  • Define which endpoints your API contains (example).

  • Define how the TypeScript interface for your API should be generated (example).

    • Run that script in order to generate the TypeScript interface file: php path/to/your/generate.php (example result)

    • You might want to run this script automatically when starting your local dev server, and check in your CI pipeline whether the committed TypeScript interface file is up-to-date.

  • Have a publicly reachable PHP script that serves the API (example).

Client side (TypeScript)

  • Install php-typescript-api using npm:

    npm install --save php-typescript-api

  • Configure your API client (example).

  • Use your API client to make requests (example).

Contribute

Build:

  • Server: (no build necessary)
  • Client: npm run build

Run tests:

  • Server: composer test
  • Client: npm test

Lint:

  • Server: composer fix
  • Client: npm run lint

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.6.137latest

Version History

VersionDownloads (Last 7 Days)Published
2.6.137
2.6.12912
2.6.110
2.6.100
2.6.90
2.6.80
2.6.70
2.6.60
2.6.50
2.6.40
2.6.30
2.6.20
2.6.10
2.6.00
2.5.04
2.4.020
2.3.016
2.2.016
2.1.110
2.1.04
2.0.33
2.0.10
2.0.00
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i php-typescript-api

Weekly Downloads

992

Version

2.6.13

License

MIT

Unpacked Size

29 kB

Total Files

15

Last publish

Collaborators

  • allestuetsmerweh