PHPackages                             laravel-restype/laravel-restype - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. laravel-restype/laravel-restype

ActiveLibrary[API Development](/categories/api)

laravel-restype/laravel-restype
===============================

0.1.1(3y ago)39MITPHPPHP ^8.0

Since Jan 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/laravel-restype/laravel-restype)[ Packagist](https://packagist.org/packages/laravel-restype/laravel-restype)[ Docs](https://github.com/laravel-restype/laravel-restype)[ RSS](/packages/laravel-restype-laravel-restype/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Laravel-RESType (BETA) - add type-safety to your RESTful API
============================================================

[](#laravel-restype-beta---add-type-safety-to-your-restful-api)

This project has 2 components:

- [**laravel-restype**](https://github.com/laravel-restype/laravel-restype) - laravel server / generates the typescript definitions
- [laravel-restype-client](https://github.com/laravel-restype/laravel-restype-client) - generic typescript client / consumes the typescript definitions generated

**Warning ! Beta software !** please don't use this in production yet !

### What is this ?

[](#what-is-this-)

I saw the tRPC project and I wanted something similar, but for my existing Laravel projects.

After a quick google search I found the awesome project [spatie/typescript-transformer](https://github.com/spatie/typescript-transformer), however the integration with laravel is very barebones, serving as a building block.

This project helps you generate TypeScript definitions for your entire existing laravel REST api. After the definition is generated, you can import it in your frontend, or download it into your react-native project.

Instalation
===========

[](#instalation)

```
composer require laravel-restype/laravel-restype:"*"
```

Publish config

```
php artisan vendor:publish --tag="laravel-restype-config"
```

Usage
=====

[](#usage)

1. First, let's enable automatic discovery for all your routes. In your `routes/api.php` file, add this empty class:

```
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript]
class ApiRoutes
{
}

Route::get('/hello-world', [HomeController::class, 'hello_world']);
```

// TODO: not the best solution. make a custom transformer for this one with a prefix parameter

2. Then, add Route definitions for every controller method that coresponds to a route.

```
use LaravelRESType\Attributes\RouteTypeScriptType;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript]
class HomeController extends Controller
{
    #[
        RouteTypeScriptType([
            'responses' => [
                [
                    'hello' => '"world"',
                    'message' => 'string',
                ],
            ],
        ])
    ]
    public $hello_world;
    public function hello_world(Request $request)
    {
        return [
            'hello' => 'world',
            'message' => 'Make the web a better place !',
        ];
    }
}
```

Note: a current limitation is that we can't generate typescript definitions for class methods, instead we have to add an empty property with the same name as the method (`public $hello_world`).

3. Generate your new typescript definition with:

```
php artisan typescript:transform
```

The default destination is: `/public/types/generated.ts`

4. Install our client typescript package in your frontend project to use your new definitions.

Follow the steps from the [client package documentation](https://github.com/laravel-restype/laravel-restype-client#readme).

Example project
===============

[](#example-project)

```
git clone https://github.com/laravel-restype/laravel-restype
cd laravel-restype/example
docker compose up -d
docker-compose exec php su app -c 'cd example; composer install'
docker-compose exec php su app -c 'cd example; cp .env.example .env; php artisan key:generate'
```

Roadmap:
========

[](#roadmap)

☐Support url parameters (eg. `/post/{id}`)☐Support file type, convert json body to FormDataChangelog:
==========

[](#changelog)

### v0.1.1 - 2023-05-01

[](#v011---2023-05-01)

- Patch - fixed method name generation for routes with params

### v0.1 - 2023-01-07

[](#v01---2023-01-07)

- First version

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~113 days

Total

2

Last Release

1107d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a265d28d3cd348ca0230b91b6e4bfc0c4a8d7389ef491e0e894ee1107c6fafd3?d=identicon)[andreitelteu](/maintainers/andreitelteu)

---

Top Contributors

[![AndreiTelteu](https://avatars.githubusercontent.com/u/5564199?v=4)](https://github.com/AndreiTelteu "AndreiTelteu (11 commits)")

---

Tags

laravelrpctypescriptREST APItype-safetytRPC

### Embed Badge

![Health badge](/badges/laravel-restype-laravel-restype/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-restype-laravel-restype/health.svg)](https://phpackages.com/packages/laravel-restype-laravel-restype)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[neuron-core/neuron-laravel

Official Neuron AI Laravel SDK.

10710.0k](/packages/neuron-core-neuron-laravel)[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2913.6k](/packages/shahghasiadil-laravel-api-versioning)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
