palabs/endpoint-bundle

Symfony Endpoint bundle

Installs: 3 032

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 2

Forks: 0

Open Issues: 1

Type:symfony-bundle

2.0.0 2021-12-24 04:59 UTC

This package is auto-updated.

Last update: 2024-03-29 21:20:01 UTC


README

PaEndpointBundle add alternative to symfony controllers. Endpoint is a controller with only one method - execute(Request): Response

Features include:

  • Simple and clean endpoint interface - only one request handler in one class
  • Easy way to generate routes, e.g. $router->url(SomeEndpoint::class)
  • Refactorable - no additional changes need if you move or rename endpoint
  • No route names need (but if you want you can specify it in route definition)
  • Supports for extending endpoints - you can define base endpoints and many childs with shared routes configuration. It's is very common task in crud controllers.

Installation

Add bundle to you composer.json:

composer require palabs/endpoint-bundle

Register bundle in Kernel:

// app/AppKernel.php

public function registerBundles()
{
    return [
        // ...
        new PaLabs\EndpointBundle\PaEndpointBundle(),
        // ...
    ];
}

Add route loading in app/config/routing.yml:

endpoints:
  resource: .
  type: endpoints

Usage

A simple endpoint look like

use PaLabs\EndpointBundle\EndpointInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class TextEndpoint implements EndpointInterface {

    public function routes()
    {
       return new Route('/cool_message');
    }
    
    
    public function execute(Request $request): Response
    {
       return new Response('Hello, world');
    }
}