PHPackages                             area17/twill-api - 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. area17/twill-api

ActiveLibrary[API Development](/categories/api)

area17/twill-api
================

v0.1.2(3y ago)149246[2 issues](https://github.com/area17/twill-api/issues)[1 PRs](https://github.com/area17/twill-api/pulls)Apache-2.0PHPPHP ^8.0

Since Jan 27Pushed 2y ago5 watchersCompare

[ Source](https://github.com/area17/twill-api)[ Packagist](https://packagist.org/packages/area17/twill-api)[ RSS](/packages/area17-twill-api/feed)WikiDiscussions 1.x Synced 1w ago

READMEChangelogDependencies (12)Versions (9)Used By (0)

Twill API
=========

[](#twill-api)

Provide a read-only API to Twill models and entities along with base structure to create your own JSON:API compliant REST API. This package is based on and requires the excellent [Laravel JSON:API](https://github.com/laravel-json-api/laravel) package.

Installation
------------

[](#installation)

This package needs a Laravel project with Twill already set up.

### Install Laravel JSON:API

[](#install-laravel-jsonapi)

Follow the steps outlined in the Laravel JSON:API [documentation](https://laraveljsonapi.io/docs/3.0/getting-started/).

Update `config/jsonapi.php` with the namespace you would like to use.

```
-    'namespace' => 'JsonApi',
+    'namespace' => 'TwillApi',
```

### Install Twill API

[](#install-twill-api)

```
composer require area17/twill-api
```

Publish config file `config/twill-api.php` and migrations. Apply migrations.

```
php artisan vendor:publish --tag=twill-api-config
php artisan vendor:publish --tag=twill-api-migrations
php artisan migrate
```

Create you base `Server.php` class

```
php artisan twill-api:server
```

Update `config/jsonapi.php` `servers` key with your newly created `Server` class.

```
'servers' => [
- //    'v1' => \App\JsonApi\V1\Server::class,
+    'v1' => \App\TwillApi\V1\Server::class,
],
```

If you want to make you API public (which is convenient early in development), you can update the `authorisable` method in your `Server` class.

```
    function authorizable(): bool
    {
-         return true;
+         return false;
    }
```

Add API middlewares you the `api` group in `app/Http/Kernel.php`. See below for a list of the available middlewares.

Middlewares
-----------

[](#middlewares)

### Middleware to set locale

[](#middleware-to-set-locale)

To query the API by adding the locale query string to the url. For example `https://example.com/api/v1/books?locale=fr` will give you the results available in the French (fr) locale.

```
    protected $middlewareGroups = [
        // ...

        'api' => [
            \A17\Twill\API\Http\Middleware\SetLocale::class,
            // ...
```

### Middleware to remove unpublished content

[](#middleware-to-remove-unpublished-content)

from browser fileds and features.

```
    protected $middlewareGroups = [
        // ...

        'api' => [
            \A17\Twill\API\Http\Middleware\EnableFeaturePublishedScope::class,
            \A17\Twill\API\Http\Middleware\EnableRelatedItemPublishedScope::class,
            // ...
```

Traits
------

[](#traits)

Whenever your models has media or files attached to them, you must add the traits provided in this package in order to expose a relationship to the pivot models for each (by default it is the `mediables` and `fileables` tables).

If your model also have children blocks (saved through repeater inside a block), you must add the `HasChildBlocks` for the API to respect the parent/child relation in the API response.

```
use A17\Twill\API\Models\Traits\HasChildBlocks;
use A17\Twill\API\Models\Traits\HasFileables;
use A17\Twill\API\Models\Traits\HasMediables;

class Page
{
    use HasChildBlocks, HasFileables, HasMediables;

    // ...
}
```

Create a resource schema and API route
--------------------------------------

[](#create-a-resource-schema-and-api-route)

To create a basic schema for a new resource (model), use the artisan command `twill-api:schema`. Pass the name of the Twill module as the argument.

```
php artisan twill-api:schema snippets
```

This command will create `app/TwillApi/V1/Snippets/SnippetSchema.php`. The command will display a few instructions to register the new schema with the API server and how to declare the endpoint in you `routes/api.php`.

For what is available from there, consult the Laravel JSON:API documentaiton under the [Schemas](https://laraveljsonapi.io/docs/2.0/schemas/) section.

Your new endpoint should now be available at `http://localhost/api/v1/snippets`.

Resources
---------

[](#resources)

### Endpoints

[](#endpoints)

This package provides these endpoints along with their schema:

- `/api/v1`
- `/api/v1/blocks`
- `/api/v1/blocks/{id}`
- `/api/v1/features`
- `/api/v1/features/{id}`
- `/api/v1/files`
- `/api/v1/files/{id}`
- `/api/v1/media`
- `/api/v1/media/{id}`
- `/api/v1/related-items`
- `/api/v1/related-items/{id}`
- `/api/v1/tags`
- `/api/v1/tags/{id}`
- `/api/v1/settings`
- `/api/v1/settings/{id}`
- `/api/v1/users`
- `/api/v1/users/{id}`

### Blocks

[](#blocks)

(to do)

```
php artisan twill-api:block-content text
php artisan twill-api:block-content my-block-name
```

### Browser fields (related items)

[](#browser-fields-related-items)

(to do)

### Features

[](#features)

(to do)

Use API tokens to show unpublished content
------------------------------------------

[](#use-api-tokens-to-show-unpublished-content)

(to do)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.1% 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 ~22 days

Total

7

Last Release

1074d ago

Major Versions

v0.1.2 → 1.x-dev2023-06-07

PHP version history (2 changes)v0.0.1PHP ^7.4|^8.0

v0.1.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13578874?v=4)[twill](/maintainers/twill)[@twill](https://github.com/twill)

---

Top Contributors

[![ptrckvzn](https://avatars.githubusercontent.com/u/6365432?v=4)](https://github.com/ptrckvzn "ptrckvzn (115 commits)")[![zeezo887](https://avatars.githubusercontent.com/u/44491331?v=4)](https://github.com/zeezo887 "zeezo887 (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/area17-twill-api/health.svg)

```
[![Health](https://phpackages.com/badges/area17-twill-api/health.svg)](https://phpackages.com/packages/area17-twill-api)
```

###  Alternatives

[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[spatie/laravel-route-discovery

Auto register routes using PHP attributes

23645.0k2](/packages/spatie-laravel-route-discovery)[codedredd/laravel-soap

A SoapClient wrapper integration for Laravel

221516.6k3](/packages/codedredd-laravel-soap)[simplestats-io/laravel-client

Client for SimpleStats!

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

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)

PHPackages © 2026

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