Coder Social home page Coder Social logo

cundd / rest Goto Github PK

View Code? Open in Web Editor NEW
78.0 13.0 24.0 10.06 MB

REST webservices for TYPO3 CMS

Home Page: https://rest.corn.rest

PHP 97.46% Shell 1.76% HTML 0.61% Dockerfile 0.17%
typo3-cms php rest rest-api webservice restful typo3 typo3-cms-extension

rest's Introduction

REST v5

The REST API for TYPO3 CMS

This branch represents the development of version 5.

  • 4.x releases can be found here
  • 3.x releases can be found here
  • 2.x releases can be found here

Please visit http://rest.corn.rest/ for installation and configuration instructions

Build Status

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in REST by you, shall be licensed as above, without any additional terms or conditions.

rest's People

Contributors

abteilung-cinter avatar cundd avatar datamints-off avatar florianx avatar jacobsenj avatar markhowellsmead avatar mattiasnilsson avatar pkerling avatar stuartmcfarlane avatar waldhacker1 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  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  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

rest's Issues

Typo3 version 11 support

Hi @cundd ,

Thanks for the amazing extension. I saw you've added the support for v11 in the feature branch. Could you share your plans about including those changes in the next release? When do you plan to do it? May be I help you to make the release happen faster?

HMAC or JWT Authentification

Hi,
I was wondering if it is possible that a HMAC or a JWT authentification will be included into this extension? The Base Auth (or the Login request) is not strong enough for our purpose.

Or what would I need to do to implement it?

Thank you!

Realurl dependency

Hi, the extension was not working for me (Typo3 8.7) until I installed realurl. It is neither mentioned in the dependencies nor in the documentation.

is querying for values possible?

Hey thanks for the very useful extension. I like it a lot and would like to create a page renderer for a SPA. The question to make this efficient would be if on the route /rest/virtual_object-content something like ?pageIdentifier=5 would be possible? Or even /rest/virtual_object-page/5/virtual_object-content would be a nice shorthand. This would allow quick fetching of the page and the page content while not having the overhead of fetching all page content.

Regards,
Simon

Documentation: "handlerClass" does not work

I was following the Website Documentation to set up a custom handler and got very confused about the "handlerClass" TypoScript setting - it does not seem to work, instead registered handlers need to follow a folder scheme (\Vendor\MyExtension\Rest\Handler, defined inside the ObjectManager).

While the scheme itself is not ideal but ok for me, maybe you should change that inside the documentation.

Or did I misunderstand something?

Great extension nonetheless :)

[BUG] double Content-Type

In my custom rest TYPO3 extension, I use the TS setting:
plugin.tx_rest.settings. responseHeaders.Content-Type = application/json

As a result of the this, my results get the right header, that is:
Content-Type: application/json;

But, because of this, the /rest/auth/login requests get the header:
Content-Type: application/json, application/json;

... which is throwing an error with some strict REST clients.
Is it an idea to remove line 122 in the file "ResponseFactory.php":
$response = $response->withHeader(Header::CONTENT_TYPE, 'application/json');

...or make it conditional?

Version development

The most recent version is updated last year (beta) and not suitable for typo3 v11. Is the REST API stilll maintained and are there plans for making the REST API suitable for TYPO3 version 11 ?

Wrong ConfigurationManager initialized in TYPO3 v11

The global TYPO3_REQUEST is not yet present in the middleware when the ConfigurationManager gets initialized.
Threfore Extbase can not determine correctly the application mode and the BackendConfigurationManager is loaded.
This leads to issues when using extbase plugins. Extbase doesn't load the plugin configurations...

Quick solution is a middleware which sets the global variable before the rest middleware.

Allow cacheLifeTime to be overwritten for given path level

Hello,
once again thanks for your work and this extension.

I`m trying to overwrite global cacheLifeTime value on the object path level, it looks like we are not able to store this value without given resourceType in function buildCache.

public function buildCache(ConfigurationProviderInterface $configurationProvider, ObjectManager $objectManager)
{
$cacheInstance = $this->getCacheInstance($configurationProvider, $objectManager);
if ($cacheInstance instanceof CacheInterface) {
$cacheInstance->setCacheLifeTime($this->getCacheLifeTime($configurationProvider));
$cacheInstance->setExpiresHeaderLifeTime($this->getExpiresHeaderLifeTime($configurationProvider));
}
return $cacheInstance;

I wrote patch for that which works for me in our project, unfortunately its hard for me to say if thats the final and proper way to do it.
CacheLifeTime_patch.txt

Best regards!

Cannot instantiate ObjectManagerInterface

Hey Daniel ,

we are using your rest extension version 5.0.0 on TYPO3 10 with PHP 7.4.

We extend our own class "DataProvider" with "\Cundd\Rest\DataProvider\DataProvider" and this causes the following Error

"error": "API Error #0 :Cannot instantiate interface Cundd\Rest\ObjectManagerInterface",

We also added the Extension\Configuration\Services.yaml in our extension with the following config:


services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

  Namespace\Extension\:
    resource: '../Classes/*'

  Cunnd\Rest\DataProvider\DataProvider: '@Namespace\Extension\Rest\DataProvider'

  Cundd\Rest\ObjectManagerInterface:
    public: true

  Cundd\Rest\DataProvider\ExtractorInterface:
    public: true

  Cundd\Rest\DataProvider\IdentityProviderInterface:
    public: true


so the ObjectManagerInterface is set to public.

Do you have any advice where to look at or did we something wrong with the configuration?

Thanks a lot.

Cheers
Christian

V6 and PHP 8.2 compatibility

I am Using PHP 8.2.4 with TYPO3 12.4.4 and I have a List of Fatal Errors because of PHP return types

  1. ServerRequestProxyTrait.php is an implementation of ServerRequestInterface, but that interface got a lot of return types in the functions

Example: Fatal error: Declaration of Cundd\Rest\Request::getProtocolVersion() must be compatible with Psr\Http\Message\MessageInterface::getProtocolVersion(): string

Solution: You add the return types to the functions

  1. Documentation/Handler/DummyRequest.php has a similar Problem I think, adding the correct return types will probably fix it

I have set 'exceptionalErrors' => 12290, in the settings.php (previously known as LocalConfiguration.php)

Feature suggestion

Hi!

First off: Thank you for a great extension!

Would it be possible to create custom caching durations on a per request basis?

I had a project where php/db operations for certain requests were somewhat intensive but those requests could then be cached for a long time (several days), as caches were then invalidated using flushByTag when content changed.

Certain other requests however could not be cached for a long time as invalidating their caches proved difficult or the content belonging to those requests changed so often that a cache duration set to a few hours was best.

As far as I can tell only the ts-setting "cacheLifeTime" can be used to influence caching durations, or am I missing something?

Don't singularize "news"

"Could not analyse class:News\Domain\Repository\NewRepository"

rest/Classes/Cundd/Rest/DataProvider/Utility.php->singularize.

Maybe you can add an TS-option to prevent this behavior.

Query Parameters

Hello, do you support query parameters? If yes, how should one define it in the routes?

Extension not working in Typo3 v9.5

Typo3 9.5
Rest 3.5

I followed installation instructions from https://rest.corn.rest/Installation/.

Log says Too few arguments to function Cundd\Rest\BootstrapDispatcher::processRequest(), 1 passed and exactly 2 expected.
Looks like core Typo3 dispatcher does not pass Response object, and passing second argument response is deprecated and will be removed in T3 v10.

Support for subdirectories (e.g. site running on devel.domain.com/project1/)

Currently there is no chance to get the extension working if the site is running under a subdirectory. I suggest either using the absRefPrefix or adding a custom setting to maintain it as follows:

\Cundd\Rest\RequestFactory
123 $pathPrefix = $this->configurationProvider->getSetting('absRefPrefix');
124 $uri = substr(str_replace($pathPrefix, "",$_SERVER['REQUEST_URI']), 6);

The corresponding setting would be
plugin.tx_rest.settings.absRefPrefix = /project1

[BUG] FrontendUserAuthentication::fetchSessionData()

I'm using basic authentication. when user is not authenticated or authentication is wrong I get following error

Uncaught TYPO3 Exception
Call to undefined method TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::fetchSessionData()

Error thrown in file
/Users/ondro/Sites/tourismustage.local/web/typo3conf/ext/rest/Classes/Cundd/Rest/SessionManager.php in line 33.

I think problem is caused by this change

Temporary fix: remove line 33 $GLOBALS['TSFE']->fe_user->fetchSessionData(); from rest/Classes/Cundd/Rest/SessionManager.php

Typo3 v8.7.1, rest v2.2.2

Handling sys_lanugage_uid in rest calls

It is more a question than an issue.
What is the best way to realize routes for getting objects in the localized way.
Calling for example a route /rest/getnews gives me all news objects for sys_language_uid = 0.
How do i get the localized objects?

I am looking forward for an answer.

By the way, i like your extension very much !!!!

Exception when applying the default configuration.

Hi, I am encountering the following exception when trying to test with version 12+.
I have used v4 and v5 before with no problems.

I know that v6 has not been released yet, but can you tell if this is a misconfiguration or a bug?

Thank you in advance.

Branch: v6
Typo3-Version: 12.4.11
Default configuration as described in : https://rest.corn.rest/Configuration/

Core: Exception handler (WEB): Uncaught TYPO3 Exception: TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::__construct(): Argument #2 ($site) must be of type TYPO3\CMS\Core\Site\Entity\Site, TYPO3\CMS\Core\Site\Entity\NullSite given, called in /var/www/html/typo3_src-12.4.11/typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 2985 | TypeError thrown in file /var/www/html/typo3_src-12.4.11/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php in line 524. Requested URL: http://host.docker.internal:8080/rest/virtual_object-gallery/ Delete similar errors

typo3scan against TYPO3 9

Here's the result scanning ext:rest with typo3scan (https://github.com/Tuurlijk/typo3scan).

Found 13 matches in 5.70s when
checking for changes and deprecations in TYPO3 9

strong weak BREAKING DEPRECATION
38.5% (5) 61.5% (8) 38.5% (5) 61.5% (8)

Classes/VirtualObject/Persistence/BackendFactory.php

Access to global array "TYPO3_DB" (strong)

26 return new V7Backend($GLOBALS['TYPO3_DB']);

Access to global array "TYPO3_DB" (strong)

35 if (!isset($GLOBALS['TYPO3_DB'])) {

Access to global array "TYPO3_DB" (strong)

39 $database = $GLOBALS['TYPO3_DB'];

Usage of class "TYPO3\CMS\Core\Database\DatabaseConnection" (strong)

41 return is_object($database) && $database instanceof \TYPO3\CMS\Core\Database\DatabaseConnection;

Classes/VirtualObject/Persistence/Backend/V7Backend.php

Usage of class "TYPO3\CMS\Core\Database\DatabaseConnection" (strong)

28 public function __construct(DatabaseConnection $connection)

Classes/Dispatcher.php

Access to array key "extConf" (weak)

307 && isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])

Access to array key "extConf" (weak)

308 && isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['rest'])

Access to array key "extConf" (weak)

310 $configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['rest']);

Classes/Bootstrap.php

Fetch of property "config" (weak)

151 $frontendController->config['config']['sys_language_uid'] = $requestedLanguageUid;

Classes/DataProvider/DataProvider.php

Call to method "getIdentityProperties()" (weak)

274 $identityProperties = $classSchema->getIdentityProperties();

Classes/Log/AbstractLogger.php

Access to array key "extConf" (weak)

22 && isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])

Access to array key "extConf" (weak)

23 && isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['rest'])

Access to array key "extConf" (weak)

25 $configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['rest']);

how to get content of languages ?

in manual it says:
Specify the GET-parameter L with the language UID

I could not find out how this works.

Example:
I have a site Setup with /de (L=0) and /en (L=1)

In TS i have:
plugin.tx_rest.settings {
languages {
de = 0
en = 1
}
}

How to get the content for the german language ?
Something like this does not work
domain.com/rest/VirtualObject-Content/0
domain.com/rest/VirtualObject-Content/L/0

Feature request: Allow to disable cache for route

hello,

I'd like to ask how to uncache specific resource. Lets say we have config like below. As far as i understand I should set -1 to not cache resource.

plugin.tx_rest.settings {
  cacheLifeTime = 1728000
  expiresHeaderLifeTime = 900
  paths {
    ins-hotels-hotels {
      path = hotels
      read = allow
      write = deny
      handlerClass = \Ins\Hotels\Rest\HotelHandler
      cacheLifeTime = -1
    }

Then in CacheFactroy.php we have function:

 private function getCacheLifetime(
        ConfigurationProviderInterface $configurationProvider,
        ResourceType $resourceType
    ): int {
        $resourceConfiguration = $configurationProvider->getResourceConfiguration($resourceType);

        $cacheLifetime = $resourceConfiguration->getCacheLifetime();
        if ($cacheLifetime > -1) {
            return $cacheLifetime;
        }

        $cacheLifetime = $configurationProvider->getSetting('cacheLifeTime');
        if ($cacheLifetime !== null) {
            return (int)$cacheLifetime;
        }

        $cacheLifetime = $configurationProvider->getSetting('cacheLifetime');
        if ($cacheLifetime !== null) {
            return (int)$cacheLifetime;
        }

        return -1;
    }

But with cacheLifeTime = -1 set in resource this condition will not match:

if ($cacheLifetime > -1) {
            return $cacheLifetime;
        }

and later it will return the default value for cacheLifeTime. So looks like this make impossible to uncache resource if we have defined fallback values.

Maybe I am getting that wrong but changing condition to:

if ($cacheLifetime >= -1) {
            return $cacheLifetime;
        } 

would solve the problem.

I would be glad to hear your opinion.
Tnx!

Adapt definition of fe_user.tx_rest_apikey

With this extensions installed no new fe_users can be created without explicitly setting a value for tx_rest_apikey, because this column is defined as
tx_rest_apikey tinytext NOT NULL
in ext_tables.sql.

Since TEXT type fields do not have default values, "NOT NULL" should be removed from the definition.
Setting an empty string instead of allowing NULL does not seems to have any advantage when not using this field.

Persistence Mapping is not respected

If I've a Model with persistence mapping

plugin.tx_myext {
    persistence {
        classes {
            Vendor\MyExt\Domain\Model\FrontendUser {
                mapping {
                    tableName = fe_users
                    recordType = Vendor\MyExt\Domain\Model\FrontendUser
                    columns {
                        felogin_forgotHash.mapOnProperty = feloginForgotHash
                    }
                }
            }
        }
    }
}

the extension searches for a table called tx_myext_domain_model_frontenduser.

cundd in TYPO3 9

Is that extension compatible with TYPO3 9 or has TYPO3 9 an out of the box solution to generate routes ?

Thanks.

TCA Migrations Typo3 8.7.22

Hi,

I just installed your extension and ran the TCA migrations option from the install tool. There are some TCA definitions which have to be revised for the current Typo3 8 version.

TCA migrations need to be applied

Check the following list and apply needed changes.

The 4th parameter 'specConf' of the field 'showitem' with fieldName = 'tx_rest_apikey' has been migrated, from TCA table "fe_users['types']['0']['showitem']"to "fe_users['types']['0']['columnsOverrides']['tx_rest_apikey']['defaultExtras']".

The 4th parameter 'specConf' of the field 'showitem' with fieldName = 'tx_rest_apikey' has been migrated, from TCA table "fe_users['types']['Tx_Extbase_Domain_Model_FrontendUser']['showitem']"to "fe_users['types']['Tx_Extbase_Domain_Model_FrontendUser']['columnsOverrides']['tx_rest_apikey']['defaultExtras']".

Best
Sebastian

Typo3 Site Handling not supported?

Rest: 3.5.0 and 4.0
Typo3: 9.5.5

Background: with version 9.2, the Site Handling was introduced and PSR-15 middlewares were introduced.

Problem description
In my specific case I have a site with a multi domain/single tree setup. The language is determined via the URL, e.g. www.domain.de maps to Language ID 0 and www.domain.com to Language ID 1.

The REST extension does not support this, it seems. The Language ID is always 0, no matter which domain used.

Findings
There is a middleware (web/typo3/sysext/frontend/Classes/Middleware/SiteResolver.php) which is taking care of resolving the language, which is not processed when the REST extension is used, since the eID handler (web/typo3/sysext/frontend/Classes/Middleware/EidHandler.php) is processed before the SiteResolver.

I tweaked web/typo3conf/ext/rest/Classes/Bootstrap.php::setRequestedLanguage the following way to make it work:

    private function setRequestedLanguage(TypoScriptFrontendController $frontendController)
    {
        $request = $GLOBALS['TYPO3_REQUEST'];

        /** @var SiteRouteResult $routeResult */
        $routeResult = GeneralUtility::makeInstance(SiteMatcher::class)->matchRequest($request);

        $request = $request->withAttribute('site', $routeResult->getSite());
        $request = $request->withAttribute('language', $routeResult->getLanguage());
        $request = $request->withAttribute('routing', $routeResult);

        $GLOBALS['TYPO3_REQUEST'] = $request;

        // Set language if defined
        $requestedLanguageUid = $routeResult->getLanguage()->getLanguageId()
            ?? $this->getRequestedLanguageUid($frontendController);

        if (null !== $requestedLanguageUid) {
            $frontendController->config['config']['sys_language_uid'] = $requestedLanguageUid;
            // Add LinkVars and language to work with correct localized labels
            $frontendController->config['config']['linkVars'] = 'L(int)';
            $frontendController->config['config']['language'] = $this->getRequestedLanguageCode();
        }
    }

however this duplicates the code from the SiteResolver middleware. Ideally the SiteResolver middleware should be processed before Bootstrap::init() is called, but I'm not sure if this is possible. I tried to change the order of the Typo3 middlewares accordingly, but without success. Potentially this could also cause side effects.

Using the L parameter is actually no option, since it is deprecated with the introduction of the new site handling.

Before digging deeper into this, I wanted to check with you if this is a known issue already.

And: Thanks for your efforts on this extension!

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.