Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eace/rest
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/eace/rest
- Owner: eaCe
- License: mit
- Created: 2023-01-28T16:33:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-11T06:20:42.000Z (about 1 year ago)
- Last Synced: 2023-12-12T07:26:58.472Z (about 1 year ago)
- Language: PHP
- Size: 78.1 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# REST API für REDAXO 5
Eine einfache Möglichkeit eine REST API in REDAXO zu erstellen.
## Route registrieren
```php
// https://domain.de/api/my-call
Rest::registerRoute([
'route' => 'my-call',
'methods' => array('POST', 'GET'),
'callback' => 'myCallbackFn',
]);function myCallbackFn($route) {
/** @var RestRoute $route */
$data = [
'lorem' => 'ipsum',
'dolor' => [
'sit' => 'amet',
]
];$route->sendContent($data);
exit;
}// https://domain.de/api/my-call/12
Rest::registerRoute([
'route' => 'my-call/{articleID}',
'methods' => array('POST', 'GET'),
'callback' => function ($route) {
$articleID = $route->getParam('articleID', 'int');
// ...
},
]);
```## Full configuration
```php
[
'route' => '/my-call/{articleID}',
'permission' => 'admin', // addon[]
'methods' => array('POST', 'GET'),
'validations' => [
'articleID' => 'int', // number, bool/boolean,
],
'callback' => static function($route) {
/** @var RestRoute $route */
$data = [
'lorem' => 'ipsum',
'dolor' => [
'sit' => 'amet',
]
];$route->sendContent($data);
exit;
},
]
```