🦌

Blog#API

Building Pages from an API with Hugo

In this article we cover a workarkound to build pages from a remote API wth Hugo. It consists of using Hugo to grab our data from a remote source using resources.GetRemote — Hugo’s own fetch API —, keep using Hugo to generate markdown files using its resources.FromString, and finally build our Hugo project with the aforementioned content files.

Enhance Your Hugo JSON API Using Custom Output Formats and Netlify Redirects

Hugo makes it super easy to build simple APIs with its built-in output formats. In my previous article, we built a fully functional JSON API. Today we’re going to extend the capabilities of this API and improve the user experience with better URLs.

At the moment our API can look up specific items, but can’t look at them in relation to each other. Say you want to know what players are in a specific team: with our current API, you can’t do that easily. To solve this, we’ll use Custom Output Formats to create another JSON route to read and use these relationships.

Build a JSON API With Hugo's Custom Output Formats

In order to make data that is “machine friendly” like this, we can expose it with a RESTful API. Normally, the quickest way to bootstrap an API like this would be to start with a popular framework like Flask or Ruby on Rails, spin up a webserver, and connect a database. We can achieve something even simpler, however, by creating a read-only API with a static site generator. In this article, we’ll use Hugo to build a JSON API using its Custom Output Formats feature.