Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC 100: Enhancing headless support in Wagtail core #100

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

thibaudcolas
Copy link
Member

@thibaudcolas thibaudcolas commented Jul 31, 2024

View as an HTML document. This RFC attempts to set a direction for Wagtail’s future headless support improvement. It covers:

  1. A definition of Wagtail’s support goals when it comes to headless support. Long-term, that’ll help us decide what headless-related capabilities should be in Wagtail itself, vs. in packages, vs. for site implementers to build. This is the most crucial thing to validate as part of the RFC process.
  2. An overview of the current areas of interest and known opportunities for improvement. This is meant more as a recap of current points of friction, gaps, opportunities, than a mandate that we must address them all.

I’ve also published a 2024 Wagtail headless survey so we get input from a bigger group of developers. Some of you might recall the 2022 survey, which helped us tremendously back then in documenting the current state. Those survey results will help us understand where it’d be most helpful to direct headless support contributions.

@thibaudcolas thibaudcolas changed the title RFC 100 RFC 100: Headless support in Wagtail core Jul 31, 2024
@ahosgood
Copy link

I had to add extra code to get redirects to work in the API - would that be helpful to have included?

@thibaudcolas
Copy link
Member Author

@ahosgood I would assume so? Redirects is a contrib module so not as "core" as some of the more fundamental aspects of the CMS, but certainly something that many sites would consider core CMS functionality.

@lb-
Copy link
Member

lb- commented Aug 3, 2024

I think it would be good to somehow include the pattern for JSON rendering using normal Page routing. Essentially each Page path can have a different request header and then return JSON instead of HTML.

It's quite an intuitive approach and aligns with how other CMSs (e.g. Adobe Experience Manager) can provide their APIs. It's not going to make sense for every installation but worth reviewing as part of this RFC.

In the abstract, this also could align with applications that may want to build out HTMX style applications, still returning HTML but providing a partial render of 'inner' HTML based on request headers.

See wagtail/wagtail#11752 & wagtail/wagtail#8374

@saevarom
Copy link

saevarom commented Aug 6, 2024

Headless was on the agenda for Wagtail Space NL but this only involved incorporating the areweheadlessyet.org website into the Wagtail documentation. The resulting PR is here: wagtail/wagtail#12039
The sprint topic discussion is here: https://paper.dropbox.com/doc/Sprint-topics-Wagtail-Space-NL-2024--CUVkcdc_H1K~k2BWz8SS9UUbAg-3rkJ5imATtyajKY2Ey1Cr#:uid=172696553243645599787735&h2=Headless-Wagtail

text/100-headless-support.md Outdated Show resolved Hide resolved
@lb-
Copy link
Member

lb- commented Sep 2, 2024

Another long-standing issue with the current API is that we cannot easily generate an OpenAPI specification

See wagtail/wagtail#6209

I would say that we must have a documented or even out of the box way to generate specifications for our APIs if we want to truly say we have headless support.

@thibaudcolas thibaudcolas changed the title RFC 100: Headless support in Wagtail core RFC 100: Enhancing headless support in Wagtail core Sep 5, 2024
text/100-headless-support.md Outdated Show resolved Hide resolved
@thibaudcolas thibaudcolas marked this pull request as ready for review December 5, 2024 15:55
@thibaudcolas
Copy link
Member Author

thibaudcolas commented Dec 5, 2024

Thank you everyone for the feedback! I’ve heavily updated the RFC. Now’s the time for further reviews and feedback (approval?) The RFC now has two well-separated sections:

  1. A definition of Wagtail’s support goals when it comes to headless support. Long-term, that’ll help us decide what headless-related capabilities should be in Wagtail itself, vs. in packages, vs. for site implementers to build. This is the most crucial thing to validate as part of the RFC process.
  2. An overview of the current areas of interest and known opportunities for improvement. This is meant more as a recap of current points of friction, gaps, opportunities, than a mandate that we must address them all.

I’ve also published a 2024 Wagtail headless survey so we get input from a bigger group of developers. Some of you might recall the 2022 survey, which helped us tremendously back then in documenting the current state. Those survey results will help us understand where it’d be most helpful to direct headless support contributions.

If you want to help

  1. Review the RFC. You’re here already so you’re aware of how this all works and how important input is.
  2. Take the survey and share it with colleagues. Should be a quick one.
  3. Upvote headless issues?

We’re not big on issue emoji reactions / votes as a way to make decision, but there’s a big corpus of existing tickets here so could be interesting. Here are all open issues sorted by theme:

Headless-related existing issues

Last thing, re long-standing issues and schema specifications: At this stage I think we need to move past the No True Scotsman chain of thought, asking ourselves whether Wagtail is truly headless or not. Wagtail is a hybrid system, it’s pretty clear. Some features aren’t headless-compatible, but clearly there’s hundreds if not thousands of headless sites out there built with Wagtail, some pretty high-profile. So yes it’s truly headless. We don’t want to mislead people, so there are gaps to fill (docs in particular), but it’s already a thing and has been for years.

@itzomen
Copy link

itzomen commented Dec 20, 2024

A frontend client like wagtail-js will make integrating wagtail for many frontend developers easier.

@thibaudcolas
Copy link
Member Author

@itzomen I’m not sure I follow your point, as you shared it, that front-end client already exists? Is there a need for more than one JS client?

@itzomen
Copy link

itzomen commented Dec 22, 2024

@itzomen I’m not sure I follow your point, as you shared it, that front-end client already exists? Is there a need for more than one JS client?

Oh no, I meant the continuous development of a JS client (could be that one or something else) will be a great addition to the efforts to promote the usage of Wagtail as a headless cms.

And this is definitely something I will like to provide support with

@thibaudcolas
Copy link
Member Author

Ah yes! that makes a lot of sense :) I just looked at the analytics on our now-retired "Are we headless yet?" website, the most-viewed page was REST API support, so a JS client working with the REST API is a big win.

@thibaudcolas
Copy link
Member Author

I have updated the RFC based on the Results of the 2024 Wagtail headless survey. Thank you to everyone who took part in that – I think it was exactly the type of input I was hoping we would get as far as setting priorities.

@laymonage @ahosgood @allcaps @lb- @dopry @zerolab would you be ok to re-review the RFC and approve or otherwise provide further feedback? It’s a pretty high-level RFC as it is, more of a statement of intentions than an implementation plan. So to be a bit more specific, in #106 we have three follow-up items shaping up that will depend on feedback here:

  • A plan to bring headless preview and userbar support in core
  • "Quick win" API and documentation improvements based on priority order expressed here
  • An official headless demo site – primarily so our contributors and maintainers can more easily work on headless improvements

@Scotchester
Copy link
Contributor

  • A plan to bring headless preview and userbar support in core
  • "Quick win" API and documentation improvements based on priority order expressed here
  • An official headless demo site – primarily so our contributors and maintainers can more easily work on headless improvements

These sounds like three really great next steps to me!

@dopry
Copy link

dopry commented Jan 31, 2025

Looks good. Personally I'd prefer to see GraphQL move towards first class treatment. I don't use REST for any headless sites anymore. The network overhead of multiple requests to assemble complex views adds a lot of latency that negatively impacts the UX. With GraphQL I get excellent tooling for code generation, specs are built in, and there is GraphIQL for exploring the model. Even if it remains an External Package it would be nice to see that it is something that is getting stronger consideration from the core team. @zerolab does a great job of supporting it. It could use quite a bit of documentation love and it could be a lot easier to work with when it comes to custom blocks, search, multisite handling. In my own project I've had to modify a lot to get it to be fully functional in my use case.. While I contribute a lot of that back, there are still pain points. It would be nice to annotate the ideal state as Improved External Package.

@auvipy
Copy link

auvipy commented Feb 2, 2025

Looks good. Personally I'd prefer to see GraphQL move towards first class treatment. I don't use REST for any headless sites anymore. The network overhead of multiple requests to assemble complex views adds a lot of latency that negatively impacts the UX. With GraphQL I get excellent tooling for code generation, specs are built in, and there is GraphIQL for exploring the model. Even if it remains an External Package it would be nice to see that it is something that is getting stronger consideration from the core team. @zerolab does a great job of supporting it. It could use quite a bit of documentation love and it could be a lot easier to work with when it comes to custom blocks, search, multisite handling. In my own project I've had to modify a lot to get it to be fully functional in my use case.. While I contribute a lot of that back, there are still pain points. It would be nice to annotate the ideal state as Improved External Package.

I don't think graphQL would be the best API for headless wagtail, but that could be an option. I would suggest following JSON:API 1.0/1.1 standard for headless REST API. Here is a old related issues #22

@dopry
Copy link

dopry commented Feb 3, 2025

@auvipy

I don't think graphQL would be the best API for headless wagtail, but that could be an option. I would suggest following JSON:API 1.0/1.1 standard for headless REST API. Here is a old related issues #22

I disagree with your assertion regarding what would be the best API, but I also wasn't suggesting abandoning REST. It still has a userbase whose needs should be met, and it is low overhead for the core team to maintain. I just prefer GraphQL, as do a lot of other frontend developers, and would prefer to see it get more consideration than it currently does.

@auvipy
Copy link

auvipy commented Feb 4, 2025

You can do graph like query with json:api

Copy link
Member

@laymonage laymonage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning, compromises, and the plan seems solid to me. I think having this RFC in is a good first step before we start any work on the actual improvements in Wagtail. Thanks for the great write-up!

Comment on lines +242 to +244
### How actively should we consider alternatives to Django REST Framework?

See [Moving REST framework forward #9270](https://github.com/encode/django-rest-framework/discussions/9270), and the popularity of [Django Ninja](https://django-ninja.dev/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're considering moving away from DRF for the next version of the API, I'd suggest making whatever package we use be optional. Right now DRF is a mandatory requirement for Wagtail installation, even if you don't use it at all. Granted, there are internal admin views that are built with DRF, but I'm sure it can be refactored to use plain Django just fine.

And then if people want to use the API, they can install Wagtail with an optional dependency group, e.g. wagtail[api].

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great to me!

@thibaudcolas
Copy link
Member Author

@dopry @auvipy thanks both! I didn’t think GraphQL would be a good candidate for core simply because it doesn’t seem that would have big advantages over the status quo. I’ve also heard good things about other implementations than Graphene. But certainly we need to invest more into it, package or no.

For the first time ever, I have an open source implementation of GraphQL I can point people to: bakerydemo-nextjs. I hope this will make it easier for me to make progress on docs at least.

@dopry
Copy link

dopry commented Feb 7, 2025

@dopry @auvipy thanks both! I didn’t think GraphQL would be a good candidate for core simply because it doesn’t seem that would have big advantages over the status quo. I’ve also heard good things about other implementations than Graphene. But certainly we need to invest more into it, package or no.

For the first time ever, I have an open source implementation of GraphQL I can point people to: bakerydemo-nextjs. I hope this will make it easier for me to make progress on docs at least.

I've never really had a problem with Graphene, I've had problems with graphene helpers, but ultimately it hasn't been a problem working with it. You need to do some optimization with your resolvers and prefetch/select_related when it's called for.

Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thibaudcolas Thank you for the incredible work here, taking on feedback and cross-linking various issues.

I am more than happy to approve in it's current state, I have added a few small comments though if they can get looked at.


### Private Pages

Password-protected pages are currently excluded from the API. There currently isn’t a way to view a password-protected page from a headless frontend.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we consider providing a mechanism for sending the password via a HTTP header instead? Especially as this 'password' is actively moving towards more of a shared secret. I know this is not the same as an API key but a namespaced header could be a suitable approach.

Copy link

@dopry dopry Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't work too well for a Static Site Generation scenario where the frontend may render an .htaccess or implement it's own authentication methodology. It would probably be better to transmit the hash and hashing details to the headless front end.

### Documentation

See [Headless docs](https://github.com/wagtail/wagtail/pull/12039) pull request. Headless support for various features needs to be covered in the developer documentation, either as a dedicated “headless support” page, or separately feature by feature, or both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to recommend that as part of our documentation tasks, we also aim to expose the full API for our Wagtail Guide https://guide.wagtail.org/en-latest/

This is a great way to show the features of the API (as is, and evolving) and may also allow developers to create new content/remixes of that Guide site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.