A Laravel 5 based REST Server for Content Management
This package complies with PSR-1, PSR-2 and PSR-4.
- PHP >= 5.5.9
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
After ensuring that you meet the above requirements, follow the below procedures for installing Laravel REST CMS
$ git clone https://github.com/ddimaria/Laravel-REST-CMS.git laravel-rest-cms
$ cd laravel-rest-cms
This assumes you have composer installed and configured to run globally. For assistance, visit https://getcomposer.org/download/
$ composer install
This creates a /vendor directory and will pull in dependenies.
$ find storage/* -type d -exec chmod 775 {} \;
$ cp .env.example to .env
After this file copy, update the attributes in .env to match your environment, database, and mail configurations.
$ php artisan key:generate
$ php artisan migrate
$ php artisan db:seed
$ phpunit
The testing goal is 100% covearge of non-vendor, non-laravel code.
$ phpunit --coverage-html --coverage-clover=coverage.clover
This system uses the thephpleague/fractal component, which is "a presentation and transformation layer for complex data output." This provides a solid foundation for relating models, transforming data, pagination responses and standardizing input parameters.
Responses are sent using the ellipsesynergie/api-response package. This ties into Fractal's Manager object for simplifying and standardizing responses.
The system implements token-based authetication with the chrisbjr/api-guard component. This nifty package plays well with Fractal and Api-Response, and fully abstracts authentication, token generation and maintenence, api rate limiting, access levels, method-level access and full api logging.
The token name is X-Authorization, and is used to authenticate requests. To authenticate, add it to the header of your request with the api_key value you receive after logging in. There are some routes that do not require api authentication.
curl --header "X-Authorization: 2ed9d72e5596800bf805ca1c735e446df72019ef" http://localhost:8000/api/v1/page/1
When returning data for collection-based endpoints, results are paginated, 15 per page.
"meta": {
"pagination": {
"total": 150,
"count": 15,
"per_page": 15,
"current_page": 3,
"total_pages": 10,
"links": {
"previous": "https://localhost/api/v1/pages/?page=2",
"next": "https://localhost/api/v1/pages/?page=4"
}
}
}
404 responses are returned with a 404 status code and a "Not found!" JSON response:
{
"error": {
"message": "Not found!",
"status_code": 404
}
}
Validation errors throw a 422 response:
{
"error": {
"code": "GEN-UNPROCESSABLE-ENTITY",
"http_code": 422,
"message": [
"The name field is required.",
"The layout field is required."
]
}
}
All models that extend \App\LaravelRestCms\BaseModel implement the \App\LaravelRestCms\CacheTrait in which are cached when saved.
POST /app/v1/user/login
{
"username": "admin",
"password": "123"
}
{
"data": {
"id": 1,
"first_name": "Admin",
"last_name": "User",
"api_key": "7fa1949b94f9000f4bb558709aee106f8c0d042c",
"version": "version: 1.0.3"
}
}
GET /app/v1/user/logout/{api_key}
{
"ok": {
"code": "SUCCESSFUL",
"http_code": 200,
"message": "User was successfuly deauthenticated"
}
}
GET /app/v1/page/{id}
{
"data": {
"id": 1,
"parent_id": 0,
"template_id": 1,
"nav_name": "Home",
"url": "home",
"title": "Home Page"
}
}
GET /app/v1/page/{id}/detail
GET /app/v1/page/{slug}
The 2 routes above get the same information. The first one keys off of the primary key (id), while the second one looks up the page by the slug.
{
"data": {
"id": 1,
"parent_id": 0,
"template_id": 1,
"nav_name": "Home",
"url": "home",
"title": "Home Page",
"detail": {
"data": [
{
"id": 1,
"page_id": 1,
"template_detail_id": 1,
"data": "First page content",
"group": 0,
"version": 0,
"template_detail": {
"data": [
{
"id": 1,
"parent_id": 0,
"name": "Main Content",
"description": null,
"var": "main_content",
"type": "wysiwyg",
"data": null,
"sort": 1
}
]
}
},
{
"id": 2,
"page_id": 1,
"template_detail_id": 2,
"data": "First page sub-content",
"group": 0,
"version": 0,
"template_detail": {
"data": [
{
"id": 2,
"parent_id": 1,
"name": "Sub Content",
"description": null,
"var": "main_content",
"type": "wysiwyg",
"data": null,
"sort": 1
}
]
}
}
]
},
"parent": {
"data": []
}
}
}
POST /app/v1/page/{id}
{
"parent_id" : 1,
"template_id" : 1,
"nav_name": "New Page",
"url": "new-page-here",
"title" : "New Page Title"
}
{
"data": {
"id": 21,
"parent_id": 1,
"template_id": 1,
"nav_name": "New Page",
"url": "new-page-here",
"title": "New Page Title"
}
}
The MIT License (MIT). Please see License File for more information.