ycrao/tinyme

a tiny php framework based on flight and medoo.

Installs: 54

Dependents: 0

Suggesters: 0

Security: 0

Stars: 39

Watchers: 6

Forks: 5

Open Issues: 0

Type:project

1.3 2019-03-30 12:00 UTC

This package is auto-updated.

Last update: 2024-12-16 22:18:28 UTC


README

Latest Stable Version Latest Unstable Version License Total Downloads

A tiny php framework based on flight and medoo.

IntroductionPage | 简体中文读我

Installation

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 http://127.0.0.1:9999 url in your browser.

API Service

Please import sql\tinyme.sql to your local MySQL database, then modify .env file configuration.

Route

API error code

post api/login

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.

Request Example

curl -X POST http://127.0.0.1:9999/api/login --data "email=foo@example.com&password=123456"

Response Example

Using 200 as code when success.

{
    "code": 200,
    "msg": "OK",
    "data": {
        "uid": "1",
        "token": "TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D",
        "expire_at": 1510233022
    }
}

Using non-2xx (403500 etc) digital when fail or error.

{
    "code": 403,
    "msg": "illegal or incorrect credentials",
    "data": []
}

get api/pages

Get current user pages with pagination.

Request Example

curl http://127.0.0.1:9999/api/pages -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"

# with page
curl http://127.0.0.1:9999/api/pages?page=2&per_page=2 -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"

Response Example

{
    "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"
            }
        ]
    }
}

post api/page

Create a new page.

Request Example

# POST raw data (in `json` format)
curl -X POST http://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 http://127.0.0.1:9999/api/page --data "content=# Hello world\n\nThis is another demo page." -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"

Response Example

{
    "code":200,
    "msg":"OK",
    "data":{
        "result":"create success!",
        "view_url":"/api/page/4"
    }
}

get api/page/@id

Get page by specified id.

Request Example

curl http://127.0.0.1:9999/api/page/4 -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"

Response Example

{
    "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"
    }
}

put api/page/@id

Update page by specified id.

Request Example

# PUT raw data (in `json` format)
curl -X PUT http://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 http://127.0.0.1:9999/api/page/4 --data "_method=put&content=# Demo\n\nThis is another demo page." -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"

Response Example

{
    "code":200,
    "msg":"OK",
    "data":{
        "result":"update success!"
    }
}

delete /api/page/@id

Delete page by specified id.

Request Example

# DELETE
curl -X DELETE http://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 http://127.0.0.1:9999/api/page/4 --data "_method=delete" -H "AUTHORIZATION: Bearer TVC66rtXnv7pw3jge4EtyC7qtyKKPxjjGyVUi4K2D"

Response Example

{
    "code":200,
    "msg":"OK",
    "data":{
        "result":"delete success!"
    }
}

Documentation

Kernel

based on mikecao/flight , official website : http://flightphp.com/ , https://github.com/mikecao/flight .

Cache

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 : http://docs.doctrine-project.org/en/latest/reference/caching.html , https://github.com/doctrine/cache .

Log

$logger = Flight::log()->debug('debug log');

based on katzgrau/klogger , official website : https://github.com/katzgrau/KLogger .

Database and Model

Flight::model('Page')->getPageByID(1);
Flight::db()->get('tm_page', '*', [
            'id' => 1
            ]);

based on catfan/medoo , official website : https://github.com/catfan/medoo , http://medoo.in/doc .

Reference

flight-app-demo

License

The TinyMe framework is open-sourced software licensed under the MIT license.