Code Monkey home page Code Monkey logo

site-endpointsexample's Introduction

Site-EndpointsExample

This extension serves as an example to show how to use site/site-endpoints for third-party-extensions.

Requirements

  • PHP +8.0
  • TYPO3 +11.3

Note that it has not been tested yet on any lower TYPO3/PHP version.

Registration of an endpoint

YAML-API
  1. Head over into the ext_localconf.php of your own extension.
  2. Add the following snippet:
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
    Site\SiteEndpoints\Provider\EndpointsProvider::class
)->loadYaml(
    TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
        'site_endpointsexample',
        'Configuration/Endpoints.yaml'
    )
);

Note: The loadYaml requires an absolute path to a YAML file which looks like this:

routes:
  - prefix: '/yaml'
    groups:
    - routePath: '/v2'
      middlewares:
        - 'Site\SiteEndpoints\Middleware\ExtbaseBridge'
      routes:
        - methods: [GET]
          routePath: '/wow'
          callback: 'Site\SiteEndpointsexample\Controller\YamlController->wow'
PHP-API
  1. Head over into the ext_localconf.php of your own extension.
  2. Add the following snippet:
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
    Site\SiteEndpoints\Provider\EndpointsProvider::class
)->add(
    (new Site\SiteEndpoints\Configuration\RouteIdentifier())
    ->setIdentifier('/identifier')
    ->addGroup(
        (new Site\SiteEndpoints\Configuration\RouteGroup())
        ->setRoutePath('/routegrouppath')
        ->addMiddleware(
            Site\SiteEndpoints\Middleware\ExtbaseBridge::class
        )
        ->addRoute(
            (new Site\SiteEndpoints\Configuration\Route())
            ->setRoutePath('/routepath')
            ->setCallback(
                Site\SiteTests\Controller\TestController::class,
                'test'
            )
        )
    )
);

So we got a new URI pathname called /identifier/routegrouppath/routepath.

RouteIdentifier – The wrapper for the RouteGroup and Route
It's strongly recommended to have an unique identifier. Specific use-cases are:

  • Kickstarting a new project? Use /api as identifier.
  • Writing a third-party-extension? Use either your extension key with dash instead of underscore e.g. /site-endpointsexample or an unique string you could come up.

RouteGroup – PSR-15 Middlewares and the next slug
/routegrouppath can be interpreted as some sort of versioning-identifier. The default setup (in YAML) shipped by site/site-endpoints delivers the routeGroupPath as /v1 which looks prefixed with the identifier as this: /api/v1.

Route – Final slug which maps with it to controller->action
/routepath is the final slug/path-segment. This one has no rules at all, feel free to write/configure this as you like.


Change those slugs/path-segments as you need them as the controller-/action names to be, flush caches and you're ready to use them!

site-endpointsexample's People

Contributors

m001s avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.