ThanosDi / jsonapi-example

Example API using phramework/jsonapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple API example using phramework/jsonapi 1.x

Build Status

Endpoints

Available endpoints:

  • GET /article/
  • GET /article/{id}/
  • GET /article/{id}/relationships/tag/
  • GET /article/{id}/relationships/author/
  • POST /article/
{
  "data": [
    {
      "type": "article",
      "attributes": {
        "title": "Sample title",
        "body": "Sample body"
      },
      "relationships": {
        "creator": {
          "data": {
            "id": "1",
            "type": "user"
          }
        }
      }
    }
  ]
}
  • GET /tag/
  • GET /tag/{id}/
  • GET /tag/{id}/relationships/article/
  • GET /user/
  • GET /user/{id}/

Install

Requirements:

To download dependencies

composer update

Run

To initialize the SQLite database schema and records (required to run only once)

php ./tools/database.php

To start local web server at port 8004 execute using php build-in server

composer run

or

php -S localhost:8004 -t ./public/

You can access the article collection using GET http://localhost:8004/article/ request.

You can also expose /public to your web server, NOTE we are using an .htaccess file to rewrite the urls.

Test

To run all available tests (syntax check, unit and request tests)

composer test
  • Unit tests available at /tests/phpunit/ directory using PHPUnit
  • Request tests available at /tests/testphase/ directory using phramework/testphase

Lint code

Lint code using PSR-2 coding style

composer lint

About

Example API using phramework/jsonapi

License:Apache License 2.0


Languages

Language:PHP 99.5%Language:ApacheConf 0.5%