google / google/fonts

New Developer API Specification

Open
#3,880 1 comment 0 reactions 1 assignee Claimed by @rsheeter View on GitHub
Dominant language
HTML
Stars
20.5k
Forks
2.9k
Avg merge
1d 21h
Merged PRs (30d)
95

Description

# Developer API

The existing [Developer API](https://developers.google.com/fonts/docs/developer_api) has aged quite much over the years (almost a decade old) and it no longer meets many requirements developers need to make effective and useful tools surrounding the Google Fonts ecosystem. Other solutions such as [google-font-metadata](https://github.com/fontsource/google-font-metadata) and [google-webfonts-helper](https://github.com/majodev/google-webfonts-helper) use a bunch of unintended scraping techniques (e.g. collecting data via the CSS API) that are prone to breakage when Google makes changes to the platform. This adds roadblocks for the Google team and creates friction between developers.

As discussed in #3870, this is a proposal for a new Developer API that should open up opportunities for developers to create new exciting projects or integrations with Google Fonts.

## Main Proposal

The [Fontsource API](https://fontsource.org/docs/api/introduction) was created as personally my ideal version of the Developer API, although I will admit it was my first ever attempt at making an API and so my knowledge may be lacking if there are any glaring faults to the design and organisation of it. I do still suggest a similar format to this API unless others have better ideas.

The URLs are up to the Google team, so I'll use placeholders.

### `GET /fonts`

Documentation Reference: https://fontsource.org/docs/api/fonts
API Example: https://api.fontsource.org/v1/fonts

### `GET /fonts/:id`

Documentation Reference: https://fontsource.org/docs/api/font-id
API Example: https://api.fontsource.org/v1/fonts/abel

This one does have an overlooked bug where fonts such as [Noto Sans JP](https://api.fontsource.org/v1/fonts/noto-sans-jp) with the numbered unicode-range subsets do not show up with their relevant files in the Fontsource API. Instead, they show off the download links to the whole `latin` and `japanese` subsets, which was the legacy behaviour of the CSS 1 API.

Ideally, I think we could set a query parameter such as `legacy=true` to allow users to toggle showing download links for how the old CSS 1 API served files with entire language subsets and the newer CSS 2 numbered subsets solution.

For added clarity to what I mean with whole language and numbered subsets:

- [Whole language](https://raw.githubusercontent.com/fontsource/google-font-metadata/ea9a978db4b5c69a00415aa9d9fceac02b7cdd3e/lib/data/google-fonts-v1.json)
- [Numbered](https://raw.githubusercontent.com/fontsource/google-font-metadata/main/lib/data/google-fonts-v2.json)

Please CTRL+F to `noto-sans-jp` as it is the best example to show off the difference.

## Variable Fonts Proposal

Variable fonts have been increasingly adopted and therefore should get its own dedicated API endpoint as part of the rework.

Fontsource has this as a pending issue and so I don't have live examples to work with: fontsource/fontsource#321

### `GET /variable`

Returns a list of all variable font objects similar to [this](https://github.com/fontsource/fontsource/blob/main/packages/cabin/metadata.json).

I'm still unsure how much overlapping data points from the main endpoint and variable endpoint we should have (e.g. weights or subsets) and therefore I have no strong opinion on this.

### `GET /variable/:id`

It's a simple expansion containing the download links to the font files. Possibly with more axis data?

## References

Original issue: #3870
CC: @rsheeter

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.