Consume REST services in your templates
MIT License
Placid allows you to consume RESTful APIs in your Statamic templates, using Guzzle to handle the requests.
Placid supports:
Require the addon via composer
composer require ritson/placid-statamic
You can set up requests for placid in resources/placid/requests like so:
// 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
You can define authorisation schemes to use and reuse on your requests. You define them in resources/placid/auth like so:
// 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:
// 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
To use this plugin in your templates, simply use these tags:
{{ placid handle="placeholder" }}
{{ response.data }}
<h1>{{ title }}</h1>
{{ /response.data }}
{{ /placid }}
{{ 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 }}
<h1>{{ title }}</h1>
{{ /response.data }}
{{ /placid }}
If you want to leave feedback about this project, feel free to get in touch on twitter if you experience any issues please just create a new issue here on the Repo