Build a JSON API With Hugo's Custom Output Formats

I believe you’re referring to part 2.

Until very recently there was no way to assign an output format to only certain pages, (pages inside a section for ex). It was either all pages or no pages at all.

    [outputs]
    page = ["json", "players"]

This is why you get the warning, as following the article walkthrough, only the pages of type teams should have a template file for the custom output at layouts/teams/single.players.json.

Now you should still get an endpoint at /teams/players.json in spite of the warning which only concern other pages (without the players template file).

Today though, to remove the warning, you can use e the cascade keyword inside content/teams/_index.md to limit the assignment to its children pages.

# content/teams/_index.md
Title: Teams
cascade:
  outputs:
    - HTML
    - JSON
    - players
# As cascade also applies to self we should overwrite here as this list page does not sport a players output (nor template file for it):
outputs
  - HTML
  - JSON

Hope this helps!

1 Like

Replying a few hours after my question on a Sunday… man, idk if it works, but i admire your predisposition and knowledge of the platform! Thanks!

I hope you can write more articles around the rest APIs, as i wanna try the approach solely to build apps around it.

I’m thinking about workshops on the matter.

In the mean time you should take a look at this:

1 Like

Just lovely! I will check it out. (I hope the component theme thing is manageable with my little knowledge on the hugo platform).