https://github.com/alecritson/placid-statamic
Consume REST services in your templates
https://github.com/alecritson/placid-statamic
statamic statamic-addon statamic-v2 statamic-v3
Last synced: 10 months ago
JSON representation
Consume REST services in your templates
- Host: GitHub
- URL: https://github.com/alecritson/placid-statamic
- Owner: alecritson
- License: mit
- Created: 2014-10-23T14:10:41.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-03-20T09:32:03.000Z (almost 2 years ago)
- Last Synced: 2025-03-15T04:03:38.270Z (10 months ago)
- Topics: statamic, statamic-addon, statamic-v2, statamic-v3
- Language: PHP
- Homepage:
- Size: 594 KB
- Stars: 54
- Watchers: 5
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Placid Statamic
[](https://styleci.io/repos/25640354)
---
Placid allows you to consume RESTful APIs in your Statamic templates, using Guzzle to handle the requests.
**Placid supports**:
- Caching/Refreshing
- Template variable pairs
- Predefined requests
- Headers
- Access tokens
### Installation
Require the addon via composer
```
composer require ritson/placid-statamic
```
### Parameters
- **host**: The API host
- **cache** (number): The time in seconds until the cache refreshes (default is 7200 / 2 hours)
- **handle** (string) : The handle of the resource to use
- **method** (string) : You can set which method to use on the request, default is 'GET'
- **query** (string) : Add your queries here, see [queries](#queries) for more info
- **path** (string) : Add your own custom path, see [paths](#paths) for details
- **auth** (string) : Handle for the auth scheme to use
### Saved requests
You can set up requests for placid in **resources/placid/requests** like so:
``` yaml
// resources/placid/requests/placeholder.yaml
host: https://jsonplaceholder.typicode.com
method: GET
path: posts/:id
auth: placeholder // See Authentication section
segments:
id: 1
headers:
accept: application/json
query:
foo: bar
formParams:
foo: bar
```
#### Authentication
You can define authorisation schemes to use and reuse on your requests. You define them in **resources/placid/auth** like so:
``` yaml
// resources/placid/auth/placeholder.yaml
headers:
Authorization: Bearer :token
token: services.api.token
```
The above will send the token through the headers, you define your tokens in your config and reference as you would any Laravel config item.
If you need to send your access token through the query string, define your auth scheme like so:
``` yaml
// resources/placid/auth/placeholder.yaml
query:
access_token: :token
token: services.api.token
```
The query string and headers will be merged with any that are already present on the request
## Usage
To use this plugin in your templates, simply use these tags:
### Basic example
```
{{ placid handle="placeholder" }}
{{ response.data }}
{{ title }}
{{ /response.data }}
{{ /placid }}
```
### Full example
```
{{ placid host="https://jsonplaceholder.typicode.com" path=":part/:id" cache="60" query="foo:bar|bar:baz" segments="part:posts|id:1" headers="foo:bar" }}
{{ response.data }}
{{ title }}
{{ /response.data }}
{{ /placid }}
```
## Support,issues,feedback
If you want to leave feedback about this project, feel free to get in touch on [twitter](http://www.twitter.com/alecritson) if you experience any issues please just create a new issue here on the Repo