PHPackages                             faisel/contao-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. faisel/contao-api

ActiveContao-bundle[API Development](/categories/api)

faisel/contao-api
=================

Access Contao content via an easy to use JSON-API

1.0.1(4y ago)0271[1 issues](https://github.com/faisel/contao-api/issues)[1 PRs](https://github.com/faisel/contao-api/pulls)MITPHPPHP ^7.0|^8.0

Since Dec 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/faisel/contao-api)[ Packagist](https://packagist.org/packages/faisel/contao-api)[ RSS](/packages/faisel-contao-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Contao Content API
==================

[](#contao-content-api)

We at [Die Schittigs](http://www.dieschittigs.de) love [Contao](https://contao.org/de/), but the web moves forward and static HTML templating just doesn't cut it anymore. Thus we came up with an easily digestible JSON-API to access Contao content via JavaScript (or anything else that can handle JSON).

With the Contao Content API it is possible to write the entire Frontend of your website in [React.js](https://facebook.github.io/react/), [Angular](https://angular.io/), [vue](https://vuejs.org/), or any other JS-framework. All while still using the great Contao Backend.

Requirements
------------

[](#requirements)

You'll need an up-and-running **Contao 4.4.x** installation. Please note that the API is **not compatible with Contao 3.x**.

Installation
------------

[](#installation)

Install [composer](https://getcomposer.org) if you haven't already, enter this command in the main directory of your Contao installation:

```
composer require dieschittigs/contao-content-api

```

Contao Content API is now installed and ready to use.

Usage
-----

[](#usage)

Once installed, the following routes are available:

##### /api/sitemap

[](#apisitemap)

Gets the sitemap including the root pages.

[Example](examples/sitemap.json)

##### /api/sitemap/flat

[](#apisitemapflat)

Gets all pages as key value pairings where the key is the URL.

[Example](examples/sitemap_flat.json)

##### /api/urls\[?file=sitemap\]

[](#apiurlsfilesitemap)

Gets all URLs from the generated sitemap XML(s). If you define a `file`, only that XML will be parsed.

[Example](examples/urls.json)

##### /api/page?url=/about/team.html

[](#apipageurlaboutteamhtml)

Gets the page, including all articles and contents at the `url`.

[Example](examples/page.json)

##### /api/newsreader?url=/news/detail/new-website.html

[](#apinewsreaderurlnewsdetailnew-websitehtml)

Gets the news reader content from the `url`

[Example](examples/newsreader.json)

##### /api/?url=/page/or/newsarticle.html

[](#apiurlpageornewsarticlehtml)

Tries to get the page at the `url`, and contents from any reader

[Example](examples/page_newsreader.json)

##### /api/user

[](#apiuser)

Gets the logged-in frontend user, if available.

[Example](examples/user.json)

##### /api/module?id=5

[](#apimoduleid5)

Gets the content of a module by id

[Example](examples/module.json)

##### /api/text?file=tl\_news,modules

[](#apitextfiletl_newsmodules)

Gets the content of a language file by filename(s)

[Example](examples/text.json)

##### /api/file?path=files/uploads&amp;depth=2

[](#apifilepathfilesuploadsdepth2)

Gets the file or directory at `path` and also it's children, limited by `depth`

[Example](examples/file.json)

All routes also take the additional `lang` parameter (e.g. `?lang=de`). If you need to override the language.

Configuration
-------------

[](#configuration)

### Disabling the API

[](#disabling-the-api)

Edit your `parameters.yml`.

```
parameters:
…
content_api_enabled:
    false
…

```

The API routes are now all disabled. This may be helpful if you only want to use the classes included in the bundle.

### Response headers

[](#response-headers)

Edit your `parameters.yml`.

```
parameters:
…
content_api_headers:
    'Access-Control-Allow-Origin': 'https://mysite.org'
…

```

These headers will be added to all responses from the API.

### Custom readers

[](#custom-readers)

Contao has the concept of Reader Module (e.g. News Reader). These can be inserted anywhere inside of an article where they read the URL to display their contents. If you want to add additional Reader Modules, you can do so by adding them in your `parameters.yml`.

```
parameters:
…
    content_api_readers:
        newsreader: NewsModel
        blogreader: BlogModel
…

```

Please note that the second parameter is the **model** class, **not the module**class. The new reader is now available at

##### /api/blogreader?url=/blog/detail/on-the-topic.html

[](#apiblogreaderurlblogdetailon-the-topichtml)

or, if you want to include the whole page, at

##### /api?url=/blog/detail/on-the-topic.html

[](#apiurlblogdetailon-the-topichtml)

Internally the API tries to instantiate the model with the alias found in the url. It also tries to add all `ContentModels` it can find.

Hooks
-----

[](#hooks)

We provide some basic hooks:

```
class Hooks{

    // $GLOBALS['TL_HOOKS']['apiBeforeInit']
    public static apiBeforeInit(Request $request){
        return $request
    }

    // $GLOBALS['TL_HOOKS']['apiAfterInit']
    public static apiAfterInit(Request $request){
        return $request
    }

    // $GLOBALS['TL_HOOKS']['apiContaoJson']
    public static apiContaoJson(ContaoJson $contaoJson, mixed $data){
        if($data instanceof ContentModel){
            $contaoJson->data = null;
            // End of the line
            return false;
        }
        // Do your thing, ContaoJson
        return true;

    }

    // $GLOBALS['TL_HOOKS']['apiResponse']
    public static apiResponse(mixed $data){
        $data->tamperedWith = true;
        return $data;

    }

    // $GLOBALS['TL_HOOKS']['apiModuleGenerated']
    public static function apiModuleGenerated(ApiModule $module, string $moduleClass)
    {
        // Override the way certain modules are handled
        if ($moduleClass != 'Contao\ModuleBlogList') {
            return;
        }
        $_module = new ModuleBlogList($module->model, null);
        $module->items = $_module->fetchItems(
            $module->category
        );
    }
}

```

Documentation
-------------

[](#documentation)

The classes crafted for the API might be a good starting point if you want to build anything on top of Contao.

[Check out the docs here](docs/ApiIndex.md)

Contribution
------------

[](#contribution)

Bug reports and pull requests are very welcome :)

---

© Die Schittigs GmbH 2019

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1604d ago

PHP version history (2 changes)1.0.0PHP ^5.6|^7.0

1.0.1PHP ^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b08f5ad31069b56c585126040b64715cc3e6b441faa8bde1bfb4acf1f06c4bd?d=identicon)[faisel](/maintainers/faisel)

---

Top Contributors

[![faisel](https://avatars.githubusercontent.com/u/8522869?v=4)](https://github.com/faisel "faisel (4 commits)")

---

Tags

jsonapibundlecontao

### Embed Badge

![Health badge](/badges/faisel-contao-api/health.svg)

```
[![Health](https://phpackages.com/badges/faisel-contao-api/health.svg)](https://phpackages.com/packages/faisel-contao-api)
```

###  Alternatives

[dieschittigs/contao-content-api

Access Contao content via an easy to use JSON-API

412.4k](/packages/dieschittigs-contao-content-api)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
