alecritson / Placid-Statamic

Consume REST services in your templates
MIT License
54 stars 1 forks source link

[V2]: Possible additions to docs & questions #13

Open markboulton opened 6 years ago

markboulton commented 6 years ago

I've been working through this trying to add various APIs and working through differing request formats and differing responses. A few questions have arisen, so I'm going to document them here (hopefully to be helpful!)

Manipulating a response It might be worth putting in the docs that the {{ response }} variable pair includes things like 'limit' and 'order_by'. Took me a little while to figure this out.

Path based query A few APIs I tried did not use a query but a path instead. For example: https://www.someapi.com/posts/[key]/[value]/[value]. Does the plugin deal with queries such as this?

alecritson commented 6 years ago

Hey @markboulton

Thanks for the feedback, I think the limit and order_by are specific to whether that's what the API you queried returns (Placid doesn't actually add anything to the response)

I can see the value in a path based query, that's true. When I wrote the plugin it was for version 1 and was loosely just a port of my other Craftcms plugin (I really just wrote it "too see if I could" as I hadn't created a Statamic plugin before). So there are definitely features lacking that could be included.

That said. I'm planning to do a complete rewrite of the plugin when I get a chance, this one will actually include screens within the Admin system. A more OOP approach to the building and sending of requests, I would also like to get OAuth implemented properly to it and just make it so it's easy to add features in the future (like form submitting).

markboulton commented 6 years ago

This is great news, Alec. Your plans sound exciting! Let me know if I can help at all. Happy to do some legwork kicking the tyres.

alecritson commented 6 years ago

I've been looking into the path based query question you had and started working on it, how do you feel about the following?

Say you had your url as: https://jsonplaceholder.typicode.com/{endpoint}/{number}/{type} and in your template:

{{ placid:request handle="posts" :segment-number="1" :segment-endpoint="posts" :segment-type="comments"}}
{{ /placid:request }}

I thought about just having :number="1" but then figured namespacing would be better to avoid conflicts with any request config. But this would then give you https://jsonplaceholder.typicode.com/posts/1/comments