Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

Content API

Jonas Keinholz edited this page Jan 22, 2019 · 11 revisions

We offer an API for all learning content on serlo.org.
(There is a separate API for the metadata of the content.)

Recommended Option

Include serlo.org content in your own application via <iframe> like

<iframe src="https://de.serlo.org/1553?contentOnly"></iframe>

contentOnly is our recommended options. It hides all elements except the content, breadcrumbs navigation and search, e.g. https://de.serlo.org/1553?contentOnly

Terms of Use

The API is free. Please contact us before using the API beyond prototyping: en@serlo.org

Further Customization

For further customization of the output we provide a couple of query strings which you can combine according to your needs like

<!-- Hide only topbar and footer -->
<iframe src="https://de.serlo.org/27801?hideTopbar&amp;hideFooter"></iframe>

Content height

We inform the parent window about the actual dimensions of our content via window.postMessage (initially and after any resize event). You can use that to give the iframe the correct height to avoid scroll bars:

window.addEventListener('message', e => {
  const { data } = e

  // Context is always `serlo`
  if (data.context !== 'serlo') {
    return
  }

  // Content width in px
  console.log(data.contentWidth)
  // Content height in px
  console.log(data.contentHeight)

  // Get the iframe somehow. You can also check `e.origin`
  const iframe = document.getElementsByTagName('iframe')[0]
  iframe.style.height = `${data.contentHeight}px`
})

Any Problems or Suggestions?

If that still doesn't fit your use case or you run into any issues, feel free to create an issue.