A tiny php framework based on flight and medoo.
Just like Laravel
installation, set public
directory as server root path in vhost.conf
and using composer
to install or update packages and so on. You can do these in your terminal like below:
//using git
git clone https://github.com/ycrao/tinyme.git tinyme
//or using composer, but skip `composer install` command below
composer create-project --prefer-dist ycrao/tinyme tinyme
cd tinyme
cp .env.example .env
vim .env
composer install
cd app
chmod -R 755 storage
php -S 127.0.0.1:9999 -t public
You can view this project page by typing https://127.0.0.1:9999
url in your browser.
Please import sql\tinyme.sql
to your local MySQL database, then modify .env
file configuration.
Method | Route or URI | Note |
---|---|---|
post |
/api/login |
Get access-token by logining account. |
get |
/api/pages |
Get current user pages with pagination. |
post |
/api/page |
Create a new page. |
get |
/api/page/@id |
Get page by specified id. |
put |
/api/page/@id |
Update page by specified id. |
delete |
/api/page/@id |
Delete page by specified id. |
Code | Note |
---|---|
500 | fail or error. |
401 (Unauthorized) | access token already expired. |
403 (Forbidden) | illegal or incorrect credentials. |
404 (Not Found) | api or route not existed. |
200 (OK) | success. |
Using email and password to login and get access token. Please recall login api when token is expired, do not call this api frequently when old token(s) not expired.
curl -X POST https://127.0.0.1:9999/api/login --data "[email protected]&password=123456"
Using 200
as code
when success.
{
"code": 200,
"msg": "OK",
"data": {
"uid": "1",
"token": "TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D",
"expire_at": 1510233022
}
}
Using non-2xx (403
、500
etc) digital when fail or error.
{
"code": 403,
"msg": "illegal or incorrect credentials",
"data": []
}
Get current user pages with pagination.
curl https://127.0.0.1:9999/api/pages -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
# with page
curl https://127.0.0.1:9999/api/pages?page=2&per_page=2 -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
{
"code": 200,
"msg": "OK",
"data": {
"total": 2,
"per_page": 2,
"current_page": 2,
"next_page_url": "/api/pages/?page=3&per_page=2",
"prev_page_url": "/api/pages/?page=1&per_page=2",
"from": "1",
"to": "1",
"data": [
{
"id": "1",
"content": "# Hello world\n\nThis is a demo page.",
"created_at": "2017-11-09 13:54:39",
"updated_at": "2017-11-09 13:54:39"
}
]
}
}
Create a new page.
# POST raw data (in `json` format)
curl -X POST https://127.0.0.1:9999/api/page --data '{"content":"# Hello world\n\nThis is another demo page."}' -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
# POST data (in form string)
curl -X POST https://127.0.0.1:9999/api/page --data "content=# Hello world\n\nThis is another demo page." -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
{
"code":200,
"msg":"OK",
"data":{
"result":"create success!",
"view_url":"/api/page/4"
}
}
Get page by specified id.
curl https://127.0.0.1:9999/api/page/4 -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
{
"code":200,
"msg":"OK",
"data":{
"id":"4",
"uid":"1",
"content":"# Hello world\n\nThis is another demo page.",
"created_at":"2017-11-09 20:36:52",
"updated_at":"2017-11-09 20:36:52"
}
}
Update page by specified id.
# PUT raw data (in `json` format)
curl -X PUT https://127.0.0.1:9999/api/page/4 --data '{"content":"# Demo\n\nThis is another demo page."}' -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
# hijack PUT method by passing `_method=put` parameter with POST
curl -X POST https://127.0.0.1:9999/api/page/4 --data "_method=put&content=# Demo\n\nThis is another demo page." -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
{
"code":200,
"msg":"OK",
"data":{
"result":"update success!"
}
}
Delete page by specified id.
# DELETE
curl -X DELETE https://127.0.0.1:9999/api/page/4 -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
# hijack DELETE method by passing `_method=delete` parameter with POST
curl -X POST https://127.0.0.1:9999/api/page/4 --data "_method=delete" -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"
{
"code":200,
"msg":"OK",
"data":{
"result":"delete success!"
}
}
based on mikecao/flight
, official website : https://flightphp.com/ , https://github.com/mikecao/flight .
if (Flight::cache('data')->contains('foo')) {
$unit = Flight::cache('data')->fetch('foo');
} else {
$bar = 'bar cache';
Flight::cache('data')->save('foo', $bar);
}
based on doctrine/cache
, official website : https://docs.doctrine-project.org/en/latest/reference/caching.html , https://github.com/doctrine/cache .
$logger = Flight::log()->debug('debug log');
based on katzgrau/klogger
, official website : https://github.com/katzgrau/KLogger .
Flight::model('Page')->getPageByID(1);
Flight::db()->get('tm_page', '*', [
'id' => 1
]);
based on catfan/medoo
, official website : https://github.com/catfan/medoo , https://medoo.in/doc .
The TinyMe framework is open-sourced software licensed under the MIT license.