Download the PHP package calvient/puddleglum without Composer
On this page you can find all versions of the php package calvient/puddleglum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download calvient/puddleglum
More information about calvient/puddleglum
Files in calvient/puddleglum
Package puddleglum
Short Description Transform Laravel models, routes, and controllers into a Typescript API client
License MIT
Homepage https://github.com/calvient/puddleglum
Informations about the package puddleglum
Puddleglum
Puddleglum allows you to automatically generate TypeScript interfaces from your Laravel models and requests as well as a typesafe Axios implementation for your API routes.
This package is based on lepikhinb/laravel-typescript. Special thanks for such an awesome package!
Introduction
If you, like Calvient, have a Laravel backend with a TS front-end (be it React, Vue, or something else), you might have noticed that you have to manually keep your TypeScript interfaces in sync with your Laravel models and requests. You might also have noticed that you have to manually keep your Axios implementation in sync with your Laravel routes.
Puddleglum is a Laravel package that solves these problems by automatically generating Typescript interfaces and a simple API implementation based on Axios.
Installation
Laravel 8 and PHP 8 are required. You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
Generate TypeScript interfaces.
Defining your requests
In Laravel, you might define your requests from the command line like this:
If you do this (i.e., your requests extend FormRequest), Puddleglum will automatically generate TypeScript interfaces for your requests. The program reads the rules from your FormRequest and generates TypeScript interfaces for your requests.
For example:
Becomes:
If you don't want to define a FormRequest (e.g., you want to use a request validator directly in your controller), you can use the GlumRequest attribute before your controller.
Example;
Defining Responses
Defining a response is a bit trickier, because PHP lacks support for generics. However, Puddleglum can still generate TypeScript interfaces for your responses.
We accomplish this by using a PHP attribute.
Example:
Using the Puddleglum Output in your TypeScript code
Import the Puddleglum client into your TypeScript code:
Then, you can use the Puddleglum client to make API calls:
The API client mirrors the PHP namespace. So, in the example
above, the login controller is at \App\Http\Controllers\Auth
and the method is named login
.
You can also import various models and requests.
License
The MIT License (MIT). Please see License File for more information.
All versions of puddleglum with dependencies
doctrine/dbal Version ^3.1
illuminate/contracts Version ^8.37|^9.0|^10.0|^11.0
spatie/laravel-package-tools Version ^1.11.0