Skip to content

phramework/jsonapi-example

Repository files navigation

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/creator/
  • POST /article/
{
  "data": [
    {
      "type": "article",
      "attributes": {
        "title": "Sample title",
        "body": "Sample body"
      },
      "relationships": {
        "creator": {
          "data": {
            "id": "1",
            "type": "user"
          }
        }
      }
    }
  ]
}
  • PATCH /article/{id}/
{
  "data": 
    {
      "type": "article",
      "id": "{id}",
      "attributes": {
        "title": "Updated title",
        "body":  "Updated body"
      }
    }
}
  • DELETE /article/{id}/
  • GET /tag/
  • GET /tag/{id}/
  • GET /tag/{id}/relationships/article/
  • GET /user/
  • GET /user/{id}/

/administrator/ API

  • GET /administrator/user/
  • GET /administrator/user/{id}/
  • POST /administrator/user/
{
  "data": [
    {
      "type": "user",
      "attributes": {
        "username": "stark 123",
        "email": "nohponex+stark123@gmail.com",
        "name": "Stark 123",
        "status": 1,
        "password": "1234"
      }
    }
  ]
}
  • PATCH /administrator/user/{id}/
{
  "data": {
    "type": "user",
    "id": "{id}",
    "attributes": {
      "name": "New name"
    }
  }
}
  • DELETE /administrator/user/{id}/

Install

Requirements:

To download dependencies

composer update

It is also recommended to install and configure Xdebug

Run

To initialize the SQLite database schema and records (required to run only once). You can reuse the command to reset the data.

php ./tools/database.php

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

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

Testphase

To execute only testphase tests

composer testphase

To generate an overview for testphase tests execute

composer testphase-report

More about writing testphase tests at https://github.com/phramework/testphase

Lint code

Lint code using PSR-2 coding style

composer lint

Local settings

Read localsettings.example.php if you need to modify any of the settings localy, without committing the changes.

About

Example API using phramework/jsonapi

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages