PHPackages                             roadiz/abstract-api-theme - 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. roadiz/abstract-api-theme

ActiveLibrary[API Development](/categories/api)

roadiz/abstract-api-theme
=========================

Exposes Roadiz content as a public REST API.

4.0.19(1y ago)21.7k[4 issues](https://github.com/roadiz/AbstractApiTheme/issues)1MITPHPPHP &gt;=7.4

Since Jan 4Pushed 1y ago4 watchersCompare

[ Source](https://github.com/roadiz/AbstractApiTheme)[ Packagist](https://packagist.org/packages/roadiz/abstract-api-theme)[ RSS](/packages/roadiz-abstract-api-theme/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (11)Versions (64)Used By (1)

Abstract API theme
==================

[](#abstract-api-theme)

**Exposes Roadiz content as a public REST API.** Mainly used in *Roadiz Headless edition*.

[![Build Status](https://camo.githubusercontent.com/fb3a13017f59493410bcfc466d36cb8b95800362ef29f9f1a7bfcf694b038d91/68747470733a2f2f7472617669732d63692e6f72672f726f6164697a2f41627374726163744170695468656d652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/roadiz/AbstractApiTheme)

*OAuth2* classes and logic are highly based on [trikoder/oauth2-bundle](https://github.com/trikoder/oauth2-bundle)which implemented [thephpleague/oauth2-server](https://github.com/thephpleague/oauth2-server) to Symfony ecosystem.

- [Configuration](#configuration)
    - [Use .env file](#use-env-file)
    - [Registering API theme](#registering-api-theme)
    - [Choose between simple *API-Key* or full *OAuth2* authentication schemes](#choose-between-simple-api-key-or-full-oauth2-authentication-schemes)
    - [Enable grant types for your website](#enable-grant-types-for-your-website)
    - [Customize CORS](#customize-cors)
    - [Use cache-tags](#use-cache-tags)
- [Create a new application](#create-a-new-application)
    - [Confidential applications: *OAuth2*](#confidential-applications-oauth2)
- [Generic Roadiz API](#generic-roadiz-api)
    - [API Route listing](#api-route-listing)
    - [OAuth2 entry points](#oauth2-entry-points)
    - [User detail entry point](#user-detail-entry-point)
    - [Listing nodes-sources](#listing-nodes-sources)
    - [Search nodes-sources](#search-nodes-sources)
    - [Listing tags per node-types](#listing-tags-per-node-types)
    - [Listing archives per node-types](#listing-archives-per-node-types)
    - [Getting node-source details](#getting-node-source-details)
    - [Getting node-source details directly from its path](#getting-node-source-details-directly-from-its-path)
    - [Listing node-source children](#listing-node-source-children)
    - [Serialization context](#serialization-context)
    - [Breadcrumbs](#breadcrumbs)
    - [Errors](#errors)
    - [Using Etags](#using-etags)

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

[](#configuration)

### Use .env file

[](#use-env-file)

This middleware theme uses `symfony/dotenv` to import `.env` variables to your project. Be sure to create one with at least this configuration:

```
JWT_PASSPHRASE=changeme
# vendor/bin/generate-defuse-key
DEFUSE_KEY=changeme
```

Your *Roadiz* entry points must initialize `DotEnv` object to fetch this configuration from a `.env` file our from your system environment (i.e. your *Docker* container environment).

### Registering API theme

[](#registering-api-theme)

- Add API base services to your project `app/AppKernel.php`:

```
# AppKernel.php
/**
 * {@inheritdoc}
 */
public function register(\Pimple\Container $container)
{
    parent::register($container);

    /*
     * Add your own service providers.
     */
    $container->register(new \Themes\AbstractApiTheme\Services\AbstractApiServiceProvider());
}
```

or in your `config.yml`:

```
additionalServiceProviders:
    - \Themes\AbstractApiTheme\Services\AbstractApiServiceProvider
```

- *You do not need to register this abstract theme* to enable its routes or translations
- Create a new theme with your API logic by extending `AbstractApiThemeApp`
- **or** use `AbstractApiThemeTrait` in your custom theme app if you already inherits from an other middleware theme,
- and add the API authentication scheme to Roadiz’ firewall-map…

### Choose between simple *API-Key* or full *OAuth2* authentication schemes

[](#choose-between-simple-api-key-or-full-oauth2-authentication-schemes)

- *API-key* scheme is meant to control your **public** API usage using a Referer regex and *non-expiring* api-key. This is a very light protection that will only work from a browser and should only be used with public data.
- *OAuth2* scheme will secure your API behind Authentication and Authorization middlewares with a short-living *access-token*.

```
