https://github.com/berxam/ranko
Minimal framework for creating RESTful APIs or simple web apps with PHP.
https://github.com/berxam/ranko
http php web
Last synced: 3 months ago
JSON representation
Minimal framework for creating RESTful APIs or simple web apps with PHP.
- Host: GitHub
- URL: https://github.com/berxam/ranko
- Owner: berxam
- License: other
- Created: 2019-11-20T05:42:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-28T02:02:16.000Z (over 5 years ago)
- Last Synced: 2025-05-10T05:36:30.833Z (11 months ago)
- Topics: http, php, web
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ranko • micro framework for web apps
Minimal framework for creating RESTful APIs or simple web apps with PHP.
## Installation
via [Composer](https://getcomposer.org)
```
composer require berxam/ranko
```
## Features
Ranko is basically just a router to which you can mount routes with their corresponding callables, a `Request` and `Response` which get passed to each forementioned callable.
- bind controller functions to HTTP methods and URLs or URL templates like `/users/:id`
- access request body and headers easily through `Request`
- respond to client with `Response` methods like `sendJSON(mixed $response)` and `render(string $view, mixed ...$params)`
## Usage
The best way to understand how this "framework" works is to just skim through the files in this repo. This whole project is less than 500 lines.
### Hello world
`index.php`:
```php
get('/hello', function ($req, $res) {
$res->sendJSON(['msg' => 'Hello world!']);
});
$app->get('/hello/:world', function ($req, $res) {
$world = $req->params['world'];
$res->sendHTML("
Hello, $world!
");
});
$app->run();
?>
```
Note that you have to direct all requests to `index.php`. If you're running PHP on an Apache server, you can use this ```.htaccess``` rewrite:
```apacheconf
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
```