47

Product support

Get help in the plugin support forum.

Categories

Getting started

  1. Authentication
  2. Request parameters
  3. Filtering & ordering query results
  4. Examples

1. Authentication

You can enable and force authentication for API requests when creating API routes. When authentication is enforced, an authentication token must be provided in the query of the request. The authentication is handled by JWT Auth API plugin.

The plugin provides 4 endpoints by default (This are provided four by JWT Auth API):

/api/login

Expects 2 parameters to receive: email and password. Makes attempt to authenticate and returns token if succeeded. Also the basic user info is included in the response.

/api/signup

Expects 3 parameters to receive: email, password and password_confirmation. Tries to create a user and returns token if succeeded. The user info is included in the response.

/api/refresh

Expects 1 parameter: token. Tries to refresh the token and return the new token.

/api/invalidate

Expects 1 parameter: token. Tries to invalidate the given token - this can be used as an extra precaution to log the user out

2. Request parameters

Parameter Required Description
Filter No To filter results using query syntax
Order No To order results using query syntax

3. Filtering and Ordering query results

Parameter Value Example
filter column1:operator:value;column2:operator:value filter=id:!in:(2);description:like:%festival
order column1:direction;colum2:direction order=id:desc;description:asc

4. Query Operators

Operator Description
is Equal to
not Not equal to
lt Less than
gt Greater than
lte Less or equal to
gte Greater or equal to
in In
!in Not In
Like Like

Examples

Get all model records:

GET: ~/api/v1/events

Get model by Id:

GET: ~/api/v1/events/278

Get Filtered models

GET: ~/api/v1/events?filter=id:!in:(2);description:like:%festival&order=id:desc

Get response example:

{
    "data" : [
        {
            "id": 2,
            "description" : "The first online festival',
            'price': 140,
            'event_date':'2018-05-08 14:00:00'
        }
        {
            'id': 3,
            'description': 'The date',
            'price': 100,
            'event_date':'2019-05-08 14:00:00'
        }
    ],
    'links': {
    'first': 'http:\/\/localhost\/api\/v1\/events?page=1',
    'last': 'http:\/\/localhost\/api\/v1\/events?page=1',
    'prev': null,
    'next': null
  },
  'meta': {
    'current_page': 1,
    'from': 1,
    'last_page': 1,
    'path': 'http:\/\/localhost\/api\/v1\/events',
    'per_page': 15,
    'to': 1,
    'total': 1
  }
}

Create new model (POST)

POST /api/v1/events?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3QvYXBpL2xvZ2luIiwiaWF0IjoxNTg1NDA4MDUxLCJleHAiOjE1ODU0MTE2NTEsIm5iZiI6MTU4NTQwODA1MSwianRpIjoiSnNrWUtnWVIxcThYS3pJcyJ9.8i2VI1Edn4sZAXMu9j6a7ZjB6FzppeRqoPp1OI3Tw1c HTTP/1.1
Content-Type: application/json

{
    "description": "hello world",
    "price": 110,
    "event_date": "2020-05-08 14:00:00"
}

Response:

{
  "statusCode": 201,
  "message": "created",
  "data": [
    {
      "description": "hello world",
      "updated_at": "2020-03-28 17:07:57",
      "created_at": "2020-03-28 17:07:57",
      "id": 18033051
    }
  ]
}

Update model (PUT)

PUT /api/v1/events/18033051?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3QvYXBpL2xvZ2luIiwiaWF0IjoxNTg1NDA4MDUxLCJleHAiOjE1ODU0MTE2NTEsIm5iZiI6MTU4NTQwODA1MSwianRpIjoiSnNrWUtnWVIxcThYS3pJcyJ9.8i2VI1Edn4sZAXMu9j6a7ZjB6FzppeRqoPp1OI3Tw1c HTTP/1.1
Content-Type: application/json

{
    "description": "hello world 2",
}

Response:

{
  "statusCode": 200,
  "message": "success",
  "data": [
    {
      "id": 18033051
      "description": "hello world 2",
      "created_at": "2020-03-28 17:07:57",
      "updated_at": "2020-03-28 17:14:46"
    }
  ]
}

Delete model (DELETE)

DELETE /api/v1/events/18033051?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3QvYXBpL2xvZ2luIiwiaWF0IjoxNTg1NDA4MDUxLCJleHAiOjE1ODU0MTE2NTEsIm5iZiI6MTU4NTQwODA1MSwianRpIjoiSnNrWUtnWVIxcThYS3pJcyJ9.8i2VI1Edn4sZAXMu9j6a7ZjB6FzppeRqoPp1OI3Tw1c HTTP/1.1

Response:

{
  "statusCode": 200,
  "message": "Model with ID: 18033051 has been deleted successfully.",
  "data": []
}
1.0.5

!!! Fixed StandardAPIController trait to enforce configuration permissions and added configurable permissions to the controller

Jun 29, 2020

1.0.4

Fixed standard endpoints name field to allow URL parameter placeholders

May 11, 2020

1.0.3

Fixed routing bugs

Apr 23, 2020

1.0.2

Fixed teeting bugs

Apr 22, 2020

1.0.1

Initialize plugin.

Mar 28, 2020