So far, I understand that the recommended way to construct API endpoints is to use twig templates. In the template, you can instantiate a collection based in the content type you previously defined in the Tailor blueprint.
What I want to accomplish now is to control the response, by means of use URL parameters. For example, given this code:
title = “Blog Posts”
layout = “default”
url = “/api/blogposts/:status?/”
[collection blogposts]
handle = “Content\BlogPost”
{% set result = collect() %}
{% for post in blogposts %}
{% do result.push({
id: post.id,
title: post.title,
email: post.author.email,
created_at: post.created_at,
updated_at: post.updated_at,
status: post.status
}) %}
{% endfor %}
{% do response(result) %}
How to select only the records that match the post ‘status’ passed in the URL, or for that matter, any other URL parameter combination?
I’m not an expert in the subject, but if we are using October CMS it is because we need to build CMS applications in a more agile and convenient way. So, given that the existing plugins have limitations, I think that the Tailor/Twig method is more adequate, since it is integrated in the core.
Of course, you could construct your API following the “Laravel way”, but it will take a lot more of time and effort, and then integrating October CMS will be overkill, IMO.