You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implementation of an API application using the Phalcon Framework (https://phalconphp.com)
9
+
Implementation of an API application using the Phalcon Framework [https://phalconphp.com](https://phalconphp.com)
10
10
11
11
### Installation
12
12
- Clone the project
13
13
- In the project folder run `nanobox run php-server`
14
14
- Hit the IP address with postman
15
15
16
-
This requires [nanobox](https://nanobox.io) to be present in your system. Visit their site for installation instructions.
16
+
**NOTE**This requires [nanobox](https://nanobox.io) to be present in your system. Visit their site for installation instructions.
17
17
18
18
### Features
19
19
##### JWT Tokens
@@ -24,65 +24,106 @@ As part of the security of the API, [JWT](https://jwt.io) are used. JSON Web Tok
24
24
- Stop execution as early as possible when an error occurs
25
25
- Execution
26
26
- NotFound - 404 when the resource requested is not found
27
-
- Payload - Check the posted JSON string if it is correct
28
27
- Authentication - After a `/login` checks the `Authentication` header
29
28
- TokenUser - When a token is supplied, check if it corresponds to a user in the database
30
29
- TokenVerification - When a token is supplied, check if it is correctly signed
31
30
- TokenValidation - When a token is supplied, check if it is valid (`issuedAt`, `notBefore`, `expires`)
32
31
32
+
##### JSONAPI
33
+
This implementation follows the [JSON API](https://jsonapi.org) standard. All responses are formatted according to the standard, which offers a uniformed way of presenting data, simple or compound documents, includes (related data), sparse fieldsets, sorting, patination and filtering.
34
+
33
35
### Usage
34
36
35
37
#### Requests
36
-
All requests to the API have be submitted using `POST`. All requests must send a JSON string with one root element `data`. Data needed for the request must be under the `data` element
|`POST`|`{"data": {"userId": 1}}`| with Bearer Authentication` |
51
-
52
-
`/usesr/get`
53
-
54
-
| Method | Payload |
55
-
|--------|---------|
56
-
|`POST`| Empty |
57
-
58
91
#### Responses
59
92
##### Structure
93
+
**Top Elements**
94
+
-`jsonapi` Contains the `version` of the API as a sub element
95
+
-`data` Data returned. Is not present if the `errors` is present
96
+
-`errors` Collection of errors that occurred in this request. Is not present if the `data` is present
97
+
-`meta` Contains `timestamp` and `hash` of the `json_encode($data)` or `json_encode($errors)`
98
+
99
+
After a `GET` the API will always return a collection of records, even if there is only one returned. If no data is found, an empty resultset will be returned.
100
+
101
+
Each endpoint returns records that follow this structure:
60
102
```json
61
103
{
62
-
"jsonapi": {
63
-
"version": "1.0"// Version of the API
64
-
},
65
-
"data": [
66
-
// Payload returned if successful reply (not present if there is an error)
67
-
],
68
-
"errors": [
69
-
"Error 1", // Collection of errors
70
-
"Error 2"
71
-
},
72
-
"meta": {
73
-
"timestamp": "2018-06-08T15:04:34+00:00", // Timestamp of the response
74
-
"hash": "e6d4d57162ae0f220c8649ae50a2b79fd1cb2c60"// Hash of the timestamp and payload (`data` if success, `error` if failure)
104
+
"id": 1051,
105
+
"type": "users",
106
+
"attributes": {
107
+
"status": 1,
108
+
"username": "niden",
109
+
"issuer": "https:\/\/niden.net",
110
+
"tokenPassword": "11110000",
111
+
"tokenId": "11001100"
75
112
}
76
113
}
77
114
```
78
-
##### 404
115
+
116
+
The record always has `id` and `type` present at the top level. `id` is the unique id of the record in the database. `type` is a string representation of what the object is. In the above example it is a `users` record. Additional data from each record are under the `attributes` node.
For more information regarding responses, please check [JSON API](https://jsonapi.org)
169
+
195
170
### TODO
196
-
- Remove `/login` endpoint. Leave the generation of the JWT to the consumer (maybe)
197
-
- Perhaps add a new claim to the token tied to the device? `setClaim('deviceId', 'Web-Server')`. This will allow the client application to invalidate access to a device that has already been logged in.
171
+
-~~Work on companies GET~~
172
+
-~~Work on relationships and data returned~~
198
173
- Write examples of code to send to the client
174
+
- Create docs endpoint
175
+
- Work on pagination
176
+
- Work on filters
177
+
- Work on sorting
178
+
- Perhaps add a new claim to the token tied to the device? `setClaim('deviceId', 'Web-Server')`. This will allow the client application to invalidate access to a device that has already been logged in.
0 commit comments