Quick Start¶
Up and running in 5 minutes¶
Install the nnrestapi extension
Follow the instructions under Installation to install the
nnrestapiextension.Create an own extension
To implement your own endpoints, you will need to create a new extension - or use one of your existing extensions.
Define the dependencies to the
nnrestapiextension in your extension. This is important, so TYPO3 loads your extension after thennrestapiextension.This goes in the
ext_emconf.phpof your extension:$EM_CONF[$_EXTKEY] = [ ... 'constraints' => [ 'depends' => [ 'nnrestapi' => '1.1.0-0.0.0', ], ], ];
In case your installation is running in composer-mode, this must be added to the
composer.jsonof your extension.{ ... "require": { "nng/nnrestapi": "^1.1" }, }Create your first endpoint
Create a file located at
Classes/Api/Demo.phpin your extension with this code.Important: Note that the comments with
@Api\Endpoint()and@Api\Access()are not just comments! They actually register your class as an Endpoint and define, who is allowed to access your method.<?php namespace My\Extension\Api; use Nng\Nnrestapi\Annotations as Api; /** * @Api\Endpoint() */ class Demo extends \Nng\Nnrestapi\Api\AbstractApi { /** * @Api\Access("public") * @return array */ public function getExampleAction() { return ['great'=>'it works!']; } }
Clear the cache!
Click on the “clear cache” icon in the backend. This will make sure, that
nnrestapirebuilds the cache file and includes your classes and endpoints.We had a focus on performance and caching, so get used to having to do this whenever you add new endpoints or make changes to the
@Api-annotations of a method.Call your endpoint
Enter the URL
https://www.yourdomain.com/api/demo/exampleto see the result!