PHPackages                             otlib/rest-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. otlib/rest-api

ActiveTypo3-cms-extension[API Development](/categories/api)

otlib/rest-api
==============

This extension allows you to create and configure RESTful API endpoints in TYPO3 using the `Otlib\\RestApi\\Api`

v1.0.2(6mo ago)3410GPL-2.0-or-laterPHPPHP ^8.0

Since Oct 23Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/othmanmajd/otlib-rest-api)[ Packagist](https://packagist.org/packages/otlib/rest-api)[ RSS](/packages/otlib-rest-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

Otlib Rest API - TYPO3 REST API Extension
=========================================

[](#otlib-rest-api---typo3-rest-api-extension)

This extension allows you to create and configure RESTful API endpoints in TYPO3 using the `Otlib\RestApi\Api`. It provides a flexible way to define routes, controllers, authentication types, and request methods, enabling developers to build robust APIs for TYPO3.

### Installation

[](#installation)

- Run the following command to install the package via Composer: ```
     composer require "otlib/rest-api"
    ```
- Or download the repository and add it to your extensions.

### Defining an API Endpoint

[](#defining-an-api-endpoint)

Use the Otlib\\RestApi\\Api class to define your API endpoints. You can set up the path, controller, method, request method, and authentication type.

### Basic Usage

[](#basic-usage)

The following example demonstrates creating a basic API endpoint that responds to GET requests. This example creates a GET endpoint at `www.[Domain].com/api/check-product-status ` that calls the 'getAll(ServerRequestInterface $request)' *method* of *ProductController*.

```
 ext_localconf.php
 __________________

 \Otlib\RestApi\Api::newApi('check-product-status')
 ->setController(ProductController::class)
 ->setMethod('getAll');
```

### Advanced Usage

[](#advanced-usage)

The following example demonstrates creating a more advanced API endpoint with custom settings:. This example creates a POST endpoint at `/_api/v2/check-product-status` check that requires Bearer token authentication and calls the 'checkProductStatus(ServerRequestInterface $request)' method of the ProductController.

```
 ext_localconf.php
 __________________

 use Otlib\RestApi\Api;
 use Otlib\RestApi\Enumeration\AuthType;
 use YourExtension\Controller\ProductController;

 Api::newApi('check-product-status')
 ->setPathPrefix('_api/v2')
 ->setController(ProductController::class)
 ->setMethod('checkProductStatus')
 ->setAuthType(AuthType::BEARER)
 ->setRequestMethod('POST')
 ->setHeaderWithNoCache(true);
```

### Authentication Types

[](#authentication-types)

The extension supports the following authentication types:

- **None:** No authentication is required.
- **Basic:** Basic authentication using a username and password.
- **Bearer:** Bearer token authentication.
- **Frontend TYPO3 User:** Authentication using TYPO3 frontend user session (fe\_typo\_user) **or** Username and Password. `$request->getParsedBody()['user'] && $request->getParsedBody()['pass']`

#### Setting Authentication

[](#setting-authentication)

```
use Otlib\RestApi\Api;
use Otlib\RestApi\Enumeration\AuthType;

Api::newApi('secure-endpoint')->setAuthType(AuthType::BEARER) ...;
```

### EventListener

[](#eventlistener)

- BeforeResponseEvent (Adjust the current request using the BeforeResponseEvent)

### Error Handling

[](#error-handling)

The extension uses custom exceptions to handle errors:

- InvalidRequestMethodException: Thrown when the request method doesn't match the API's configuration.
- MethodNotFoundException: Thrown when the specified controller method doesn't exist.
- ApiPathNotSetException: Thrown when the API path is not set.

### JSON Response for Errors

[](#json-response-for-errors)

The middleware will return a JsonResponse with appropriate HTTP status codes and messages for errors, such as unauthorized access (401 Unauthorized) or method not found.

### Running the Extension

[](#running-the-extension)

- Define your API endpoints in your TYPO3 extension's setup.
- Make requests to the API using tools like Postman, curl, or custom clients.
- Secure endpoints using the supported authentication types.

Example Code
------------

[](#example-code)

```
ext_localconf.php
__________________

use Otlib\RestApi\Api;
use Otlib\RestApi\Enumeration\AuthType;
use YourExtension\Controller\ProductController;

// Create a public API endpoint (/api/product-info) -> (ProductController::class)->getProductInfo(ServerRequestInterface $request)
Api::newApi('product-info')
->setController(ProductController::class)
->setMethod('getProductInfo')
->setRequestMethod('GET')
->setAuthType(AuthType::NONE);

// Create a protected API endpoint with Bearer token authentication (/api/product-info) -> (ProductController::class)->getProductInfo(ServerRequestInterface $request)
Api::newApi('product-info')
->setController(ProductController::class)
->setMethod('getProductInfo')
->setRequestMethod('POST')
->setAuthType(AuthType::BEARER)
->setHeaderWithNoCache(true);
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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 ~193 days

Total

3

Last Release

185d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/394bf735c9d75a406435d8cafff95b434bf2a10b4fa2bacaf7de7d728148c6c6?d=identicon)[majd.othman](/maintainers/majd.othman)

---

Top Contributors

[![devmajdothman-bot](https://avatars.githubusercontent.com/u/254765962?v=4)](https://github.com/devmajdothman-bot "devmajdothman-bot (1 commits)")

---

Tags

apiextensionREST APIbackendtypo3typo3-rest-api

### Embed Badge

![Health badge](/badges/otlib-rest-api/health.svg)

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

###  Alternatives

[b13/slimphp-bridge

Provides a middleware for registering Slim PHP applications within TYPO3 Frontend Sites

2047.2k1](/packages/b13-slimphp-bridge)[dotzero/yii2-amocrm

Расширение для Yii Framework 2 реализующее клиент для работы с API amoCRM

1639.7k](/packages/dotzero-yii2-amocrm)

PHPackages © 2026

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