Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Wagtail as an API layer

My company is evaluating Wagtail as a CMS for parts of our website. Currently we're running Python 2.7 and Django 1.5 (don't ask...). We have the ability to run Wagtail on a separate instance which can include the most current versions of Python/Django but we will not be able to run Wagtail out of the box within our main application.

We're looking at using Wagtail strictly as a CMS, then proxying requests from our main website to the Wagtail instance and returning just the generated markup.

Is there anyone who has done something like this, of could offer insight into the process we might take? Does Wagtail offer functionality like this out of the box? What potential pitfalls might we encounter, or things we should watch out for?

This could mean that instead of "entire pages" stored in Wagtail, we treat it as a way to store distinct content fragments: A paragraph of text which would be loaded into our homepage, or the outer wrapper of a dynamic search results page.

like image 859
commadelimited Avatar asked Jul 03 '18 13:07

commadelimited


People also ask

Is wagtail a headless CMS?

Headless Wagtail and other headless CMSs are pretty new, so there will be fewer developers and agencies with experience supporting them. If you absolutely need something stable and well-tested, then traditional Wagtail might be a better fit for you.

What is orderable wagtail?

Orderables let you add movable content to your page without needing a StreamField. In this video, we'll create a Bootstrap 4 Image Gallery on our Home Page model using an Orderable.

Is wagtail a opensource?

Wagtail is open source. We've chosen the BSD license, so it's both free from costs, and free from strings. No more monthly licensing charges! And we're here to support and encourage a global community of developers to make Wagtail better and better.


1 Answers

Yes, Wagtail does offer functionality like this, via its API:

http://docs.wagtail.io/en/v2.1/advanced_topics/api/

You could consume the API from the front-end of your main website, using JavaScript (React and Vue are popular options for this approach, but they aren't necessary if you don't need a complex Single Page Application with routing etc), or from the back-end, making HTTP requests from the views of your Django 1.5 app.

As for potential pitfalls, the main issue is that Wagtail previews won't work out of the box, since Wagtail doesn't know about how the content will be rendered. If you have a predictable URL structure on the site that's rendering Wagtail API content, the preview mechanism can be configured to handle this.

If the API approach isn't what you have in mind, you could also consider ways of embedding rendered fragments in the main site. For example, if you use Varnish in front of the main site, you could take advantage of Edge Side Includes:

https://varnish-cache.org/docs/3.0/tutorial/esi.html

Finally, you may find this recent talk on Wagtail as a 'headless' CMS useful:

  • https://www.youtube.com/watch?v=HZT14u6WwdY (video)
  • https://docs.google.com/presentation/d/1ZYMogOeXKCCmr7hDZnzx0euw2pD5VCwtv3a7zHB4FW0/ (slides)
  • https://github.com/openstax/openstax-cms (code)
like image 175
tomd Avatar answered Sep 19 '22 13:09

tomd