{"id":13675059,"url":"https://github.com/DieSchittigs/contao-content-api-bundle","last_synced_at":"2025-04-28T22:32:17.877Z","repository":{"id":53782440,"uuid":"88170064","full_name":"DieSchittigs/contao-content-api-bundle","owner":"DieSchittigs","description":"Contao JSON-API","archived":false,"fork":false,"pushed_at":"2022-11-16T15:06:22.000Z","size":145,"stargazers_count":41,"open_issues_count":9,"forks_count":9,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-11T16:41:11.499Z","etag":null,"topics":["api","contao","contao-bundle","contao-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DieSchittigs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-13T13:52:02.000Z","updated_at":"2023-06-19T05:38:47.000Z","dependencies_parsed_at":"2023-01-23T11:15:15.900Z","dependency_job_id":null,"html_url":"https://github.com/DieSchittigs/contao-content-api-bundle","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DieSchittigs%2Fcontao-content-api-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DieSchittigs%2Fcontao-content-api-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DieSchittigs%2Fcontao-content-api-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DieSchittigs%2Fcontao-content-api-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DieSchittigs","download_url":"https://codeload.github.com/DieSchittigs/contao-content-api-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251397737,"owners_count":21583065,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","contao","contao-bundle","contao-extension"],"created_at":"2024-08-02T12:00:28.479Z","updated_at":"2025-04-28T22:32:15.547Z","avatar_url":"https://github.com/DieSchittigs.png","language":"PHP","funding_links":[],"categories":["Extensions"],"sub_categories":["English"],"readme":"# Contao Content API\n\nWe at [Die Schittigs](http://www.dieschittigs.de) love\n[Contao](https://contao.org/de/), but the web moves\nforward and static HTML templating just doesn't cut it anymore. Thus we came up\nwith an easily digestible JSON-API to access Contao content via JavaScript\n(or anything else that can handle JSON).\n\nWith the Contao Content API it is possible to write the entire Frontend of your\nwebsite in [React.js](https://facebook.github.io/react/), [Angular](https://angular.io/), [vue](https://vuejs.org/), or any other\nJS-framework. All while still using the great Contao Backend.\n\n## Requirements\n\nYou'll need an up-and-running **Contao 4.4.x** installation.\nPlease note that the API is **not compatible with Contao 3.x**.\n\n## Installation\n\nInstall [composer](https://getcomposer.org) if you haven't already,\nenter this command in the main directory of your Contao installation:\n\n    composer require dieschittigs/contao-content-api\n\nContao Content API is now installed and ready to use.\n\n## Usage\n\nOnce installed, the following routes are available:\n\n##### /api/sitemap\n\nGets the sitemap including the root pages.\n\n[Example](examples/sitemap.json)\n\n##### /api/sitemap/flat\n\nGets all pages as key value pairings where the key is the URL.\n\n[Example](examples/sitemap_flat.json)\n\n##### /api/urls[?file=sitemap]\n\nGets all URLs from the generated sitemap XML(s). If you define a `file`, only that XML will be parsed.\n\n[Example](examples/urls.json)\n\n##### /api/page?url=/about/team.html\n\nGets the page, including all articles and contents at the `url`.\n\n[Example](examples/page.json)\n\n##### /api/newsreader?url=/news/detail/new-website.html\n\nGets the news reader content from the `url`\n\n[Example](examples/newsreader.json)\n\n##### /api/?url=/page/or/newsarticle.html\n\nTries to get the page at the `url`, and contents from any reader\n\n[Example](examples/page_newsreader.json)\n\n##### /api/user\n\nGets the logged-in frontend user, if available.\n\n[Example](examples/user.json)\n\n##### /api/module?id=5\n\nGets the content of a module by id\n\n[Example](examples/module.json)\n\n##### /api/text?file=tl_news,modules\n\nGets the content of a language file by filename(s)\n\n[Example](examples/text.json)\n\n##### /api/file?path=files/uploads\u0026depth=2\n\nGets the file or directory at `path` and also it's children, limited by `depth`\n\n[Example](examples/file.json)\n\nAll routes also take the additional `lang` parameter (e.g. `?lang=de`). If you\nneed to override the language.\n\n## Configuration\n\n### Disabling the API\n\nEdit your `parameters.yml`.\n\n    parameters:\n    …\n    content_api_enabled:\n        false\n    …\n\nThe API routes are now all disabled. This may be helpful if you only\nwant to use the classes included in the bundle.\n\n### Response headers\n\nEdit your `parameters.yml`.\n\n    parameters:\n    …\n    content_api_headers:\n        'Access-Control-Allow-Origin': 'https://mysite.org'\n    …\n\nThese headers will be added to all responses from the API.\n\n### Custom readers\n\nContao has the concept of Reader Module (e.g. News Reader). These can be\ninserted anywhere inside of an article where they read the URL to display\ntheir contents. If you want to add additional Reader Modules, you can do\nso by adding them in your `parameters.yml`.\n\n    parameters:\n    …\n        content_api_readers:\n            newsreader: NewsModel\n            blogreader: BlogModel\n    …\n\nPlease note that the second parameter is the **model** class, **not the module**\nclass. The new reader is now available at\n\n##### /api/blogreader?url=/blog/detail/on-the-topic.html\n\nor, if you want to include the whole page, at\n\n##### /api?url=/blog/detail/on-the-topic.html\n\nInternally the API tries to instantiate the model with the alias found in the url.\nIt also tries to add all `ContentModels` it can find.\n\n## Hooks\n\nWe provide some basic hooks:\n\n```\nclass Hooks{\n\n    // $GLOBALS['TL_HOOKS']['apiBeforeInit']\n    public static apiBeforeInit(Request $request){\n        return $request\n    }\n\n    // $GLOBALS['TL_HOOKS']['apiAfterInit']\n    public static apiAfterInit(Request $request){\n        return $request\n    }\n\n    // $GLOBALS['TL_HOOKS']['apiContaoJson']\n    public static apiContaoJson(ContaoJson $contaoJson, mixed $data){\n        if($data instanceof ContentModel){\n            $contaoJson-\u003edata = null;\n            // End of the line\n            return false;\n        }\n        // Do your thing, ContaoJson\n        return true;\n\n    }\n\n    // $GLOBALS['TL_HOOKS']['apiResponse']\n    public static apiResponse(mixed $data){\n        $data-\u003etamperedWith = true;\n        return $data;\n\n    }\n\n    // $GLOBALS['TL_HOOKS']['apiModuleGenerated']\n    public static function apiModuleGenerated(ApiModule $module, string $moduleClass)\n    {\n        // Override the way certain modules are handled\n        if ($moduleClass != 'Contao\\ModuleBlogList') {\n            return;\n        }\n        $_module = new ModuleBlogList($module-\u003emodel, null);\n        $module-\u003eitems = $_module-\u003efetchItems(\n            $module-\u003ecategory\n        );\n    }\n}\n```\n\n## Documentation\n\nThe classes crafted for the API might be a good starting point if you want\nto build anything on top of Contao.\n\n[Check out the docs here](docs/ApiIndex.md)\n\n## Contribution\n\nBug reports and pull requests are very welcome :)\n\n---\n\n© Die Schittigs GmbH 2019\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDieSchittigs%2Fcontao-content-api-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDieSchittigs%2Fcontao-content-api-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDieSchittigs%2Fcontao-content-api-bundle/lists"}