google / fonts

Font files available from Google Fonts, and a public issue tracker for all things Google Fonts
https://fonts.google.com
18.19k stars 2.61k forks source link

New Developer API Specification #3880

Open ayuhito opened 3 years ago

ayuhito commented 3 years ago

Developer API

The existing 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 and 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 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 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:

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.

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

rsheeter commented 3 years ago

Most appreciated, ty