GithubHelp home page GithubHelp logo

aoepeople / typo3_restler Goto Github PK

View Code? Open in Web Editor NEW
30.0 33.0 17.0 2.98 MB

restler (PHP REST-Framework) for TYPO3

License: GNU General Public License v3.0

PHP 99.61% Shell 0.39%
typo3 typo3-extension restler

typo3_restler's Introduction

Restler for TYPO3

Tests Code Coverage Scrutinizer Code Quality

This is a TYPO3-Extension, that integrates the popular PHP REST-framework Restler in TYPO3.

Download / Installation

You can download and install this extension from the TER (TYPO3 Extension Repository) or use composer.

composer require aoe/restler

Versions and Support

Release TYPO3 PHP Fixes will contain
12.x.y 12.4 8.1-8.3 Features, Bugfixes, Security Updates
11.x.y 11.5 7.4-8.3 Security Updates
10.x.y 10.4-11.5 7.2-7.4 End of life
9.x.y 9.5 7.2-7.4 End of life
8.x.y 8.7 7.2-7.4 End of life

Documentation

The documentation is available online at docs.typo3.org.

To render the documentation locally, please use the official TYPO3 Documentation rendering Docker Tool. https://github.com/t3docs/docker-render-documentation

Copyright / License

Copyright: (c) 2015 - 2024, AOE GmbH License: GPLv3, http://www.gnu.org/licenses/gpl-3.0.en.html

typo3_restler's People

Contributors

andreaoe avatar aoekrz avatar bnf avatar derhansen avatar develth avatar eyecatchup avatar fabarea avatar infabo avatar kschu91 avatar patrickroos77 avatar sandritter avatar soda-2005 avatar soee avatar sourcesoldier avatar srotsch avatar stefanmasz avatar sven-carstens avatar thomasschuster avatar tlayh avatar tmotyl avatar tomasnorre avatar tomschenk avatar vdespa-collab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typo3_restler's Issues

initializeBackendEndUser not compatible with TYPO3 v10.4

Since the extensions is marked as compatible with TYPO3 10.4, there should be a workaround / switch for the new TYPO3 bootstrap.

References:

For v10.4, the initializeBackendEndUser does not work any more. Code needs to be refactored like:

    public function initializeBackendEndUser()
    {
        if(!class_exists('\TYPO3\CMS\Core\Configuration\ExtensionConfiguration')) {
            if ($this->isBackEndUserInitialized === true) {
                return;
            }

            Bootstrap::initializeBackendUser();
            Bootstrap::initializeBackendAuthentication(true);
            Bootstrap::initializeLanguageObject();
        }

        $this->isBackEndUserInitialized = true;
    }

Note, the code above is not tested. I have an own BeUserAuthenticationController similar to the one in ext:restler, which I had to refactor as shown above.

Remove "cache_" prefix

Core: Error handler (BE): TYPO3 Deprecation Notice: Accessing a cache with the "cache_" prefix as in "restler" is not necessary anymore, and should be called without the cache prefix. in /var/www/html/vendor/typo3/cms-core/Classes/Cache/CacheManager.php line 112 "

I am using not the default cache-backend for EXT:restler, namely NullBackend locally and RedisBackend on production.
When I open the Install Tool, the automatic migration rewrites the the cache-name from cache_restler to just restler.

As I am using helhum config handling with YAML config, the auto migration can't complete because the wizard can't modify YAML files and the migration ends in a loop.

My suggestion: Please adjust all your usages of "restler" to restler like:

https://github.com/AOEpeople/TYPO3_Restler/blob/11.0.6/ext_localconf.php#L48
and
https://github.com/AOEpeople/TYPO3_Restler/blob/11.0.6/ext_localconf.php#L55

Open for discussion.

TYPO3 11.5.30

CarController: "/api/motorsport/cars" actually returns error

First of all: It is unclear, what numbers are valid for $id in the car controller. 1, 2, 3 all return errors. (There is no way to create "Car" records; maybe because the Repositories are missing?)

Second: when calling the api in the frontend (not within the api_explorer), I would it expect to return all cars. But it does not. As a matter of fact the "/api/motorsport/cars" route REQUIRES the id – not sure if that is really correct? Or why is that? Shouldn't this route be reserved to return ALL cars?

Bildschirmfoto 2021-07-16 um 15 51 49

Thank you!

ClassLoading fails

When I try to inject a repository I get the following error message;

{ "error": { "code": 500, "message": "Internal Server Error: Could not analyse class: \"TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManager\" maybe not loaded or no autoloader? Class TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManager does not exist" }, "debug": { "source": "ClassInfoFactory.php:35 at call stage", "stages": { "success": [ "get", "get", "route", "negotiate", "validate" ], "failure": [ "call", "message" ] } } }

The typo3 installation I'm working on is not a composer install and points right to the typo3 dir, as the customer has no shell access, thus cannot create links.
I changed the path in System\TYPO3\Loader::getClassLoader to point to "/../../../../../../vendor/autoload.php" which allowed me to install restler ext and make it work.

Any hint what goes wrong?

I already deleted typo3temp/autoloader and typo3temp/Cache/Code directories.
What puzzle me a is that there is no class from TYPO3\ in autoload_classmap.php - I would expect it to be there...

v9 Create and Delete extbase Objects

Hello!

I made some endpoints to my extbase extension. Creating Objects work - but no deletion.
After checking the pid of the objects (that i created via the API), they are all set to 0. In the restler_examples Extension the 'old' (non v9) configuration is given and that sets a specific pageUid in the Controller (that creates or deletes). This way does not seems to exist anymore.
How is it done now via the middleware? Should that be done by that feature?

Current Code for create and delete (removed the null / duplicate checks for better readability):

Create:

/**
   * Creates a EventFavorite for given Client
   *
   * @url POST /event/{eventUid}/{clientIdentifier}
   * @status 201
   *
   * @param integer $eventUid ID of the event to favorite
   * @param string $clientIdentifier ID of the client that owns the favorite
   *
   * @return void
*/
public function createFavorite($eventUid, $clientIdentifier): void
{
    $client = $this->clientRepository->findByClientIdentifier($clientIdentifier);
    $event = $this->eventRepository->findByIdentifier($eventUid);

    $favorite = new EventFavorite();
    $favorite->setEvent($event);
    $favorite->setClient($client);

    $this->eventFavoriteRepository->add($favorite);
    $this->persistenceManager->persistAll();
}

Delete:

/**
   * Removes a EventFavorite for given Client
   *
   * @url DELETE /event/{eventUid}/{clientIdentifier}
   *
   * @param integer $eventUid ID of the event to unfavorite
   * @param string $clientIdentifier ID of the client that owns the favorite
   *
   * @return void
*/
public function removeFavorite($eventUid, $clientIdentifier): void
{
    $client = $this->clientRepository->findByClientIdentifier($clientIdentifier);
    $this->eventFavoriteRepository->remove($favorite);
}

I already debugged the remove function of the Repository - the addedObjects is empty.

Thanks & Best
Thomas

Fatal error caused by wrong path in Loader

Calling /api_explorer/ results in a fatal error:
[Sat Mar 12 21:02:50.152534 2016] [:error] [pid 4084] [client 10.0.2.2:56738] PHP Fatal error: require(): Failed opening required '/var/www/html/typo3conf/ext/restler/Classes/System/TYPO3/../../../../../../../typo3_src/vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/typo3conf/ext/restler/Classes/System/TYPO3/Loader.php on line 140 [Sat Mar 12 21:02:50.152975 2016] [:error] [pid 4084] [client 10.0.2.2:56738] PHP Stack trace: [Sat Mar 12 21:02:50.153372 2016] [:error] [pid 4084] [client 10.0.2.2:56738] PHP 1. {main}() /var/www/html/typo3conf/ext/restler/Scripts/restler_dispatch.php:0 [Sat Mar 12 21:02:50.153741 2016] [:error] [pid 4084] [client 10.0.2.2:56738] PHP 2. Aoe\\Restler\\System\\TYPO3\\Loader->initializeTypo3() /var/www/html/typo3conf/ext/restler/Scripts/restler_dispatch.php:29 include path should be 'DIR . '/../../../../../../typo3_src/vendor/autoload.php''
(6 levels up instead of 7)

  • TYPO3 version 7.6.4
  • restler version 1.2.13 installed from TER
  • restler_examples 0.6.0 installed from TER
  • typo3_src is a symlink to the src folder

TYPO3 v9 compatibility

Hello AOEpeople,

I am a little bit confused about the version constraints and the compatibility with TYPO3 v9.

The composer.json implies a compatibility with TYPO3 =< 7.6.0 the ext_emconf.php restricts it to 7.6.0-8.7.99. I don't know, if TYPO3 still checks the ext_emconf.php in composermode.

Are the pull requests about the TYPO3 v9 compatibility stale? Or is this extension already v9 compatible?

Also confusing: the latest release in the TYPO3 extension repository is 2.0.2 but the latest release here on Github is 3.1.3.

It would be nice, if you could bring some light in this.

Thanks and best,
Gianni

Calling api_explorer fails with 404 when required extension is set to restler_examples

When setting restlers extension manager option
basic.extensionsWithRequiredExtLocalConfFiles = restler_examples
calling hostname/api_explorer/ returns:
{ "error": { "code": 404, "message": "Not Found" }, "debug": { "source": "Routes.php:458 at route stage", "stages": { "success": [ "get" ], "failure": [ "route", "negotiate", "message" ] } } }
and an exception is logged:
Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1428562059: No restler-configuration-class found (at least one restler-configuration-class is required)! The configuration-class must be registered in ext_localconf.php of your TYPO3-extension like this: $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['restler']['restlerConfigurationClasses'][] = '[YourConfigurationClass]';The configuration-class must implement this interface: Aoe\Restler\System\Restler\ConfigurationInterface | InvalidArgumentException thrown in file /var/www/html/typo3conf/ext/restler/Classes/System/Restler/Builder.php in line 108. Requested URL: http://localhost:8333/api_explorer/
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['restler']['restlerConfigurationClasses'] = [ 0 => Aoe\Restler\System\Restler\Configuration 1 => Aoe\RestlerExamples\System\Restler\Configuration ]

  • TYPO3 version 7.6.4
  • restler version 1.2.13
  • restler_examples version 0.6.0

Expected behaviour: read restler_examples' configuration and show api explorer

Requirement "luracast/restler" version with date suffix - no matching package found

Usage (for me):
composer require aoe/restler ^3.2.0 (PHP 7.2, TYPO3 8.7)

But with all other versions < 3.2.0 too.

Problem:

  • Installation request for aoe/restler ^3.2.0 -> satisfiable by aoe/restler[3.2.0].
  • aoe/restler 3.2.0 requires luracast/restler 3.0.0.20191001 -> no matching package found.

The GitHub and Packagist releases for package "luracast/restler" shows versions without date suffix ("20191001"). So, the tags are not available (anymore).

Workaround (before require "aoe/restler"):
composer require luracast/restler "3.0.0 as 3.0.0.20191001"

Local File Disclosure

Hello I'Find in the last version of restler (1.7.0) for Typo3 Vulnerability in File getsource.php

Line :

  1.  $file = $_GET['file'];
    
  2.    $text = file_get_contents($file);
    
  3.  die($file . '<pre id="php">' . htmlspecialchars($text) . "</pre>");
    

This allow attacker read any file in website.

Proof : https://i.imgur.com/zObmaDD.png

on pictures i'read file LocalConfiguration.php
LocalConfiguration.php Stores Credentials Information

.

Using url versioning

Hi guys,
I'd like to know if there's a way to use Url Versioning
The api is called on www.example.com/api/v[0-9]/* but the restler class in
public/typo3conf/ext/restler/vendor/luracast/restler/vendor/Luracast/Restler/Restler.php
search the url version in the first character of the requested path

Typo3 version : 8.7.10
Rester version: 2.0.2
PHP version : 7.1.3

typo3cache doesn’t respect defaultGetVars

When setting the cache entry the defaultGetVars are going into GET vars (via TSFE->getConfigArray()) and are thus added to cache identifier.
When fetching the entry (RestApiRequest->handle()) it seems that the defaultGetVars are not respected so that the cache entry is never found.
Example:
config.defaultGetVars.L = 1
/api/myendpoint/ doesn‘t use the cache
/api/myendpoint/?L=0 uses the cache.

Require ([..]/autoload.php) failed

After installing in a pure composer installation with 7.6.6 i got the error (when opening the /api_explorer):

Warning: require(/var/www/domains/[...]/web/typo3conf/ext/restler/Classes/System/TYPO3/../../../../../../../typo3_src/vendor/autoload.php): failed to open stream: No such file or directory in /var/www/domains/[...]/web/typo3conf/ext/restler/Classes/System/TYPO3/Loader.php on line 140

After i did the following change in /web/typo3conf/ext/restler/Classes/System/TYPO3/Loader.php:
$classLoader = require __DIR__ . '/../../../../../../../typo3_src/vendor/autoload.php'; (L:140)
to
$classLoader = require __DIR__ . '/../../../../../../../vendor/typo3/cms/vendor/autoload.php';
it worked.

I have this in my composer.json:

"extra": {
    "typo3/cms": {
      "cms-package-dir": "{$vendor-dir}/typo3/cms",
      "web-dir": "web"
    }
  }

Add an option to easily change request language

What is the proper way to change the request language used by Restler?

From what i see the language used by frontend controller is set in https://github.com/AOEpeople/TYPO3_Restler/blob/main/Classes/System/TYPO3/Loader.php#L213 using the site default language.

In one of our projects we base on the Accept-Language header and having custom middleware executed before Restlers' Dispatcher we can set request argument language and language aspect based on this header value. But it is ignored by Reslter when it initializes frontend rendering through Loader::initializeFrontendRendering(). We could probably add hook into TypoScriptFrontendController::settingLanguage() function and modify the language aspect there but i think the middleware layer is better place to handle it.

What do you think about changing the Loader::initializeFrontendRendering() function to create the Requets object this way:

$request = $this->getRequest()
    ->withAttribute('site', $site)
    ->withAttribute('routing', $pageArguments)
    ->withAttribute('language', $this->getRequest()->getAttribute('language'))
    ->withAttribute('normalizedParams', $normalizedParams)
    ->withQueryParams($_GET)
    ->withCookieParams($_COOKIE);

so here we fetch the SiteLanguage object from the language request attribute $this->getRequest()->getAttribute('language') and we can easily modify it through middlewares.

Cyclic middleware dependencies in restler v9

After upgrading restler from v7 to v9.0.1 on TYPO3 9.5.30
I'm getting "#1381960494 UnexpectedValueException
Your dependencies have cycles. " error

(1/1) #1381960494 UnexpectedValueException
Your dependencies have cycles. That will not work out. Cycles found: aoe/restler/system/dispatcher->typo3/cms-frontend/page-resolver, typo3/cms-adminpanel/initiator->typo3/cms-frontend/authentication, 
typo3/cms-adminpanel/initiator->typo3/cms-frontend/backend-user-authentication, typo3/cms-adminpanel/initiator->typo3/cms-frontend/tsfe, typo3/cms-adminpanel/sql-logging->typo3/cms-frontend/authentication, 
typo3/cms-adminpanel/sql-logging->typo3/cms-frontend/backend-user-authentication, typo3/cms-core/normalized-params-attribute->typo3/cms-frontend/timetracker, 
typo3/cms-frontend/authentication->typo3/cms-frontend/tsfe, typo3/cms-frontend/backend-user-authentication->typo3/cms-frontend/tsfe, typo3/cms-frontend/base-redirect-resolver->aoe/restler/system/dispatcher,
 typo3/cms-frontend/base-redirect-resolver->typo3/cms-frontend/site-resolver, typo3/cms-frontend/eid->typo3/cms-frontend/preprocessing, typo3/cms-frontend/page-resolver->typo3/cms-adminpanel/initiator,
 typo3/cms-frontend/page-resolver->typo3/cms-frontend/authentication, typo3/cms-frontend/page-resolver->typo3/cms-frontend/backend-user-authentication, 
typo3/cms-frontend/page-resolver->typo3/cms-frontend/preview-simulator, typo3/cms-frontend/page-resolver->typo3/cms-frontend/site, typo3/cms-frontend/page-resolver->typo3/cms-frontend/static-route-resolver, typo3/cms-frontend/page-resolver->typo3/cms-frontend/tsfe, typo3/cms-frontend/page-resolver->typo3/cms-redirects/redirecthandler,
 typo3/cms-frontend/preprocessing->typo3/cms-core/normalized-params-attribute, 
typo3/cms-frontend/preview-simulator->typo3/cms-frontend/authentication, typo3/cms-frontend/preview-simulator->typo3/cms-frontend/backend-user-authentication, typo3/cms-frontend/site->typo3/cms-adminpanel/sql-logging, typo3/cms-frontend/site->typo3/cms-core/normalized-params-attribute, typo3/cms-frontend/site->typo3/cms-frontend/authentication, typo3/cms-frontend/site->typo3/cms-frontend/backend-user-authentication,
 typo3/cms-frontend/site->typo3/cms-frontend/tsfe, 
typo3/cms-frontend/static-route-resolver->aoe/restler/system/dispatcher, typo3/cms-frontend/static-route-resolver->typo3/cms-frontend/base-redirect-resolver, typo3/cms-frontend/tsfe->typo3/cms-frontend/eid, 
typo3/cms-redirects/redirecthandler->typo3/cms-frontend/authentication,
 typo3/cms-redirects/redirecthandler->typo3/cms-frontend/static-route-resolver, 
typo3/cms-redirects/redirecthandler->typo3/cms-frontend/tsfe

TS-Configuration not fully loaded

Calling ViewControllers via controllers in restler ext, the fe initialisation is not fully loaded.
E.g. configuration changes from templates are not reflected / parsed.
I already tried to leave the ext_localconf-import field empty.

My use case:
I'm calling the femanager NewViewController->createAction to create users via REST API using the \TYPO3\CMS\Extbase\Mvc\Dispatcher method.

Cannot load extension in EM

When cloning the extension (in an attempt to allow future dev on it and pull requests), and after running composer install, the extension cannot be loaded in EM (6.2.16-dev) since it fails with:

#1382276561: The package "restler" depends on "luracast/restler" which is not present in the system

Compatibility to 8

Hello,

sadly the extension isn't working with TYPO3 8 - are there plans to upgrade?

unable to install aoe/restler via composer

composer req aoe/restler says:

  - aoe/restler[10.3.0, ..., 10.3.1] require luracast/restler 5.0.10.20220329 -> found luracast/restler[dev-features/AOP, dev-features/explorer, dev-features/swagger1.2, dev-features/swagger2.0, dev-master, dev-features/proxy-api, 3.0.0-RC4, ..., v3.x-dev, 4.0.0, ..., v4.x-dev, 5.0.0, ..., v5.x-dev, v6.x-dev] but it does not match the constraint.
    - Root composer.json requires aoe/restler ^10.3 -> satisfiable by aoe/restler[10.3.0, 10.3.1].

As far as I see, there is no version 5.0.10.20220329 of luracast/restler:
https://packagist.org/packages/luracast/restler

My system:
TYPO3 11.5.12
PHP 7.4.30
composer 2.3.7

Calling either "/api_explorer/" or e.g. "api/internal_endpoint/cars/2/" triggers Call to undefined method TYPO3\CMS\Core\Cache\Backend\NullBackend::getCacheDirectory()

I recently installed both the EXT:restler and EXT:restler_examples. When trying to call either the api_explorer or an endpoint, I receive an exception.

Call to undefined method TYPO3\CMS\Core\Cache\Backend\NullBackend::getCacheDirectory() 

Error thrown in file ./typo3conf/ext/restler/Classes/System/Restler/Builder.php in line 191.

TYPO3 version: 7.6.21
Rester version: 2.0.1
RestlerExamples version: 1.0.0
PHP version: 7.0.22

Invalid requirements in composer.json

Hi, I just tried to update a project which requires aoe/restler. This fails with the message below.

Obviously in your composer.json a non-existing version 3.0.0.20170425 of package luracast/restler is required.

Could you please update your composer.json with valid constraints.
(See https://packagist.org/packages/luracast/restler)

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)                                                             
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - aoe/restler 1.6.9 requires luracast/restler 3.0.0.20170111 -> no matching package found.
    - aoe/restler 1.6.8 requires luracast/restler 3.0.0.20170111 -> no matching package found.
    - aoe/restler 1.6.7 requires luracast/restler 3.0.0.20170111 -> no matching package found.
    - aoe/restler 1.6.6 requires luracast/restler 3.0.0.20170111 -> no matching package found.
    - aoe/restler 1.6.5 requires luracast/restler 3.0.0.20161104 -> no matching package found.
    - aoe/restler 1.6.4 requires luracast/restler 3.0.0.20161104 -> no matching package found.
    - aoe/restler 1.6.3 requires luracast/restler 3.0.0.20161104 -> no matching package found.
    - aoe/restler 1.6.2 requires luracast/restler 3.0.0.20161027 -> no matching package found.
    - aoe/restler 1.6.10 requires luracast/restler 3.0.0.20170425 -> no matching package found.
    - aoe/restler 1.6.1 requires luracast/restler 3.0.0.20160915 -> no matching package found.
    - aoe/restler 1.6.0 requires luracast/restler 3.0.0.20160915 -> no matching package found.
    - dwenzel/t3events-rest dev-develop requires aoe/restler ^1.6 -> satisfiable by aoe/restler[1.6.0, 1.6.1, 1.6.10, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9].
    - Installation request for dwenzel/t3events-rest dev-develop -> satisfiable by dwenzel/t3events-rest[dev-develop].

7 LTS Compatibility

Hi there,
is this extension working properly with 7LTS? I'm getting some exception.
image

Regards,
Juan Manuel

Intelephense complains about "undefined types"

Any idea why intelephense in VScode complains about what is shown in the screenshot? Whatever result I get on Google, the solution should be to implement the class and the namespace. At least the classes are implemented.

Any insights?

Bildschirmfoto 2021-07-16 um 15 45 02

Installation fails on ddev TYPO3 10.4.17, php 7.4

I use
ddev composer require aoe/restler

and get this error message:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires aoe/restler ^10.1 -> satisfiable by aoe/restler[10.1.0].
    - aoe/restler 10.1.0 requires luracast/restler 3.0.0.20200415 -> found luracast/restler[dev-features/AOP, dev-features/explorer, dev-features/swagger1.2, dev-features/swagger2.0, dev-master, 3.0.0-RC4, ..., v3.x-dev, 4.0.0, ..., v4.x-dev, 5.0.0, ..., v5.x-dev] but it does not match the constraint.


Installation failed, reverting ./composer.json and ./composer.lock to their original content.
composer [require aoe/restler] failed, composer command failed: exit status 2. stderr=

Using -W does not help.
What is the proper installation routine?

v10.3.2: TYPO3 Exception - $restlerBuilder must not be accessed before initialization

Hi,
with Version 10.3.2 I am experiencing an Exception. The complete error message from my log:
Core: Exception handler (WEB): Uncaught TYPO3 Exception: Typed property Aoe\Restler\System\RestlerBuilderAware::$restlerBuilder must not be accessed before initialization | Error thrown in file /var/www/myproject/public/typo3conf/ext/restler/Classes/System/RestlerBuilderAware.php in line 54
In Version 10.3.1, everything works fine.

Error when installing TYPO3_restler with composer

If you require
"aoe/restler": "1.*"
in your project compose,json, you will get error on running composer install/update:
Problem 1 - aoe/restler 1.5.6 requires luracast/restler 3.0.0.20160315 -> no matching package found.

Unterschied zwischen GET und POST?

Hallo,

seit ein paar Tagen versuche ich eine Schnittstelle mit Restler aufzubauen. Grundsätzlich habe ich sowohl GET-, als auch POST-Actions zum Laufen gebracht.

Nun allerdings möchte ich mit der Schnittstelle auf Models zugreifen, welche von der 'fe_users' aus TYPO3 erben. Hierfür habe ich in den Beispielen folgende Funktion gefunden:
$this->loader->initializeFrontEndRendering($pageUid);
Diese schien soweit auch zu funktionieren. Beim Abfragen einer Liste aller Datensätze aus dem entsprechenden Repository kam keine Fehlermeldung mehr.

/**
     * GET Action
     *
     * @url GET pages/{pageUid}
     * @param integer $pageUid {@min 1} The page-UID of your root-TYPO3-page
     * @return array {@type stdClass}
     */
    public function getAllKundes($pageUid)
    {
        $this->loader->initializeFrontEndRendering($pageUid);

        $restKundes = array();

        foreach ($this->kundeRepository->getAllArray() as $extbaseKunde) {
            /* @var $extbaseKunde Kunde */
            $restKunde = new stdClass();
            $restKunde->uid = $extbaseKunde->getUid();
            $restKunde->firstname = $extbaseKunde->getFirstName();
            $restKundes[] = $restKunde;
        }

        return $restKundes;
    }

Nun ist das Problem, dass ich auch eine POST-Action brauche, welche einen neuen Datensatz anlegen soll. Wenn ich hier die oben genannte Funktion verwendet, bekomme ich die Meldung: "Method Not Allowed". Falls ich sie allerdings wieder weg lasse, wir das TCA und somit auch das Mapping für die 'fe_users' nicht mehr geladen und er versucht eine Tabelle für 'verkaeufer' zu finden, welche nicht vorhanden ist.

Beide Repositorys sind auch ganz normal eingebunden:

/**
     * kundeRepository
     *
     * @var \myext\Domain\Repository\KundeRepository
     * @inject
     */
    protected $kundeRepository = NULL;

    /**
     * verkaeuferRepository
     *
     * @var \myext\Domain\Repository\VerkaeuferRepository
     * @inject
     */
    protected $verkaeuferRepository = NULL;
  /**
    * POST Action
    *
    * @url POST new
    * @status 201
    *
    * @param $data {@from body}
    * @throws RestException 400 Kunde is not valid
    * @return stdClass
    */
   public function newKunde($data)
   {
       $this->loader->initializeFrontEndRendering(1);

       $verkaeufer = $this->verkaeuferRepository->findByUid($data['uid']);

       try {
           $newKunde = new Kunde();
           $newKunde->setFirstName($data['firstname']);
           $newKunde->setLastName($data['lastname']);
           $newKunde->setVerkaeufer($verkaeufer);

           $this->kundeRepository->add($newKunde);
           $this->persistenceManager->persistAll();

       } catch(RestApiRequestException $e) {
           $this->throwRestException(self::HTTP_STATUS_CODE_BAD_REQUEST, 1446132826, $e->getMessage(), $e);
       }

   }

Durch mehrere Versuche ist mir allerdings aufgefallen, dass das Problem nicht auftritt, wenn ich zuerst eine GET-Action aufrufe, welche das FrontEndRendering initialisiert und erst dann den POST sende. Es scheint also tatsächlich nur an der Funktion zu legen.

Gibt es einen bestimmten Grund, warum diese in POST-Actions nicht erlaubt ist? Bzw. gibt es einen eleganteren Weg das Problem zu lösen? Danke.

Route does not matches when there is only a detail route

Hi,

i just started using this extension - thanks for the great work!

My current setup is TYPO3 9.5 and i´m on branch feature/typo3-9-support

Currently i just have a Controller that outputs a array - it worked:

/**
 * Get Items
 *
 * @url GET test
 * @return array
 */
 public function getItems()
 {
   $arr = array();
   for($i = 0; $i < 20; $i++){
     $arr[] = 'item'.$i;
   }
   return $arr;
 }

Everything worked fine.
After that i tried to use parameter:

/**
 * Get Items
 *
 * @url GET test/{count}
 * @param integer $count
 * @return array
 */
 public function getItems($count)
 {
  $arr = array();
   for($i = 0; $i < $count; $i++){
     $arr[] = 'item'.$i;
   }
   return $arr;
 }

It resulted in an error. I started debugging and recognized that $this->isRestlerUrl in the Dispatcher will fail.
After going into the function, i recognized that it tries to strpos /api/test/20with api/test/{count}, what fails.
If i add a default function (GET or POST ) with only @url GET test the call with the parameter works.

IMHO there is missing a way that checks if a parameter URL is valid, too

Thanks & best regards
Thomas

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.