https://github.com/augustmiller/kirby-json-transformer
A quick JSON API builder for Kirby resources
https://github.com/augustmiller/kirby-json-transformer
json kirby kirby-plugin
Last synced: about 1 month ago
JSON representation
A quick JSON API builder for Kirby resources
- Host: GitHub
- URL: https://github.com/augustmiller/kirby-json-transformer
- Owner: AugustMiller
- Created: 2017-01-10T21:35:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-18T04:47:30.000Z (almost 8 years ago)
- Last Synced: 2025-03-04T09:30:14.480Z (over 1 year ago)
- Topics: json, kirby, kirby-plugin
- Size: 1.95 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Kirby JSON Transformer
The general goal here is to create a sort "presentation and transformation layer" for JSON a la [Fractal](http://fractal.thephpleague.com/), in Kirby.
It should accomplish a few things:
- Make it easy to translate data structures defined in Blueprints into arrays that can be passed to `json_encode` or Kirby's `response::json` methods.
- Expose "resources" or "transformers" to custom routes or [Content Representations](https://getkirby.com/docs/developer-guide/advanced/representations) with only a Blueprint's key
- Offer out-of-the-box filterability for whitelisted attributes
- Support an attribute blacklist for data that ought not be exposed
- Provide query metadata
- Have sane defaults or automatic behavior, but support extension when joins or more advanced/custom transformations are needed
Ultimately, passing data from the back- end to dynamic front-end components should be simpler— out-of-the-box, it requires a lot of boilerplate and basic attribute transformation (i.e. `$resource->field_name()->toString()`).
As mentioned above, the recent addition of [Content Representations](https://getkirby.com/docs/developer-guide/advanced/representations) are a great step, and the output of this plugin ough to be compatible with a basic `template.json.php` representation definition.
# Notes
I'll update this with ideas, until a time when past supporting work can be extracted and packaged into plugin.
- Review [`JsonSerializable` interface](https://secure.php.net/JsonSerializable) to see if we couldn't shim this in without a plugin, i.e. via Kirby's custom page models:
```php
class MyTemplatePage extends Page implements JsonSerializable {
public function jsonSerialize () { return [ /* ... */ ]; }
}
```
- What we're really describing here is a GraphQL extension. Is there any sense in replicating a great deal of that spec, when we might be able to shim in proper GraphQL support? Maybe a plugin exists already?
:deciduous_tree: