Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Usage Milestone: Time Field for Drupal 8+ Module time_field crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

API Wrapper

Security covered Drupal 9โ€“11
View on drupal.org

This Drupal module automatically exposes service methods as HTTP endpoints using PHP 8 Attributes. It generates API documentation without manual route configuration by scanning annotated services. The module dynamically registers routes and provides a Swagger-like user interface for exploring your API.

๐Ÿ‡ต๐Ÿ‡ธ

A Drupal module that allows you to automatically expose service methods as HTTP endpoints using PHP 8 Attributes, and to generate a Swagger-like API documentation page without writing YAML routes manually.
The module scans services annotated with #[ApiWrap] and #[Endpoint], dynamically registers routes, and builds a navigable API documentation UI.

๐Ÿง  Core Concepts

#[ApiWrap] Attribute (Class-level)

Marks a service as an API wrapper and defines its base configuration.

Arguments

Name Type Description basePath string Base URL path for all endpoints label string API display name description string API description docPath string Custom documentation route (optional)

If docPath is omitted:

/api-wrapper/docs/{basePath}

#[Endpoint] Attribute (Method-level)

Defines a public API endpoint for a service method.

Arguments

Name Type Description method string HTTP method path string Endpoint path label string Human-readable label description string Endpoint description

๐Ÿ”€ Dynamic Route Generation

Routes are generated at runtime by ApiWrapperRoutesProvider.

GET /dummy-json/users/{id}
POST /dummy-json/carts/add

If a method parameter has a default value, an additional route is generated.

๐Ÿ”ง Supported Method Parameters

  • Scalar types โ†’ Path parameters
  • Symfony Request โ†’ Ignored
  • Default values โ†’ Route defaults

๐Ÿ“š API Documentation System

  1. Services scanned via Reflection
  2. Endpoint metadata collected
  3. Stored in Drupal State:
api_wrapper.documentation.{apiName}
  • Rendered by ApiWrapperDocumentationController
  • Twig theme: api_wrapper_documentation

๐ŸŒ Documentation Routes

/api-wrapper/docs/{apiName}

Or custom via docPath.

๐ŸŽจ Swagger-like UI

  • Grouped endpoints
  • HTTP badges
  • Parameter list
  • Clickable GET endpoints
  • Base URL display
  • Light/Dark toggle (localStorage)

๐ŸŽจ Customizing the API Documentation Theme

The API wrapper module provides a default Twig template:
api-wrapper-documentation.html.twig

You can customize the documentation UI by providing your own Twig template
inside your custom module or theme.

How to override

  1. Create a templates/ folder in your module or theme (if missing).
  2. Create api-wrapper-documentation.html.twig.
  3. Copy the default template structure and adjust HTML, CSS, or Twig logic.
  4. Clear cache (drush cr or admin UI).

๐Ÿงช Example API Implementation

#[ApiWrap(...)]
final class DummyJsonApi {

  #[Endpoint(method: 'GET', path: 'users')]
  public function users(): JsonResponse {}

  public function user(int $id): JsonResponse {}

  public function carts(): JsonResponse {}

  public function cart(int $id): JsonResponse {}

  #[Endpoint(method: 'POST', path: 'carts/add')]
  public function addCart(array $cartData): JsonResponse {}
}

Generated routes:

GET  /dummy-json/users
GET  /dummy-json/users/{id}
GET  /dummy-json/carts
GET  /dummy-json/carts/{id}
POST /dummy-json/carts/add

๐Ÿ” Permissions

access content

โš ๏ธ Limitations

  • No OpenAPI export
  • No schema generation
  • No POST body docs
  • Internal APIs focus

๐Ÿš€ Possible Future Improvements

  • OpenAPI 3.0
  • Schema support
  • Per-endpoint permissions
  • Query params
  • Auth helpers

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Jan 2026
Latest release
7 months ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Slowing

Releases

Version Type Core Release date
1.0.1 Stable 9โ€“11 Jan 30, 2026
1.0.0 Stable 9โ€“11 Jan 30, 2026