Skip to content

Commit 947e0d1

Browse files
committed
Work on the README
1 parent fb9b89a commit 947e0d1

File tree

2 files changed

+64
-100
lines changed

2 files changed

+64
-100
lines changed

README.md

Lines changed: 64 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# phalcon-api
22
Sample API using Phalcon
33

4-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/niden/phalcon-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/niden/phalcon-api/?branch=master)
5-
[![Code Coverage](https://scrutinizer-ci.com/g/niden/phalcon-api/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/niden/phalcon-api/?branch=master)
6-
[![Build Status](https://scrutinizer-ci.com/g/niden/phalcon-api/badges/build.png?b=master)](https://scrutinizer-ci.com/g/niden/phalcon-api/build-status/master)
4+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phalcon/phalcon-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phalcon/phalcon-api/?branch=master)
5+
[![Code Coverage](https://scrutinizer-ci.com/g/phalcon/phalcon-api/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/phalcon/phalcon-api/?branch=master)
6+
[![Build Status](https://scrutinizer-ci.com/g/phalcon/phalcon-api/badges/build.png?b=master)](https://scrutinizer-ci.com/g/phalcon/phalcon-api/build-status/master)
77

88

9-
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)
1010

1111
### Installation
1212
- Clone the project
1313
- In the project folder run `nanobox run php-server`
1414
- Hit the IP address with postman
1515

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.
1717

1818
### Features
1919
##### JWT Tokens
@@ -29,18 +29,63 @@ As part of the security of the API, [JWT](https://jwt.io) are used. JSON Web Tok
2929
- TokenVerification - When a token is supplied, check if it is correctly signed
3030
- TokenValidation - When a token is supplied, check if it is valid (`issuedAt`, `notBefore`, `expires`)
3131

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+
3235
### Usage
3336

3437
#### Requests
3538
The routes available are:
3639

37-
| Method | Route | Payload |
38-
|--------|-------------------|-------------------------------------------------------------------------------------------------------------|
39-
| `POST` | `login` | `{"username": string, "password": string}` |
40-
| `POST` | `companies` | `{"name": string, "address": <string>, "city": <string>, "phone": <string>` |
41-
| `GET` | `individualtypes` | `/<typeId>` If no `id` passed, all records returned. If yes, then the record matching that `id` is returned |
42-
| `GET` | `producttypes` | `/<typeId>` If no `id` passed, all records returned. If yes, then the record matching that `id` is returned |
43-
| `GET` | `users` | `/<userId>` If no `id` passed, all records returned. If yes, then the record matching that `id` is returned |
40+
| Method | Route | Parameters | Action |
41+
|--------|--------------------|------------------------------------|----------------------------------------------------------|
42+
| `POST` | `login` | `username`, `password` | Login - get Token |
43+
| `POST` | `companies` | `name`, `address`, `city`, `phone` | Add a company record in the database |
44+
| `GET` | `companies` | | Get companies. Empty resultset if no data present |
45+
| `GET` | `companies` | Numeric Id | Get company by id. 404 if record does not exist |
46+
| `GET` | `individuals` | | Get individuals. Empty resultset if no data present |
47+
| `GET` | `individuals` | Numeric Id | Get individual by id. 404 if record does not exist |
48+
| `GET` | `individual-types` | | Get individual types. Empty resultset if no data present |
49+
| `GET` | `individual-types` | Numeric Id | Get individual type by id. 404 if record does not exist |
50+
| `GET` | `products` | | Get products. Empty resultset if no data present |
51+
| `GET` | `products` | Numeric Id | Get product by id. 404 if record does not exist |
52+
| `GET` | `product-types` | | Get product types. Empty resultset if no data present |
53+
| `GET` | `product-types` | Numeric Id | Get product type by id. 404 if record does not exist |
54+
| `GET` | `users` | | Get users. Empty resultset if no data present |
55+
| `GET` | `users` | Numeric Id | Get user by id. 404 if record does not exist |
56+
57+
#### Relationships
58+
59+
`/companies/<number>/individuals`
60+
`/companies/<number>/products`
61+
`/companies/<number>/individuals,products`
62+
63+
`/companies/<number>/relationships/individuals`
64+
`/companies/<number>/relationships/products`
65+
`/companies/<number>/relationships/individuals,products`
66+
67+
`individuals/<number>/companies`
68+
`individuals/<number>/individual-types`
69+
`individuals/<number>/companies,individual-types`
70+
71+
`individuals/<number>/relationships/companies`
72+
`individuals/<number>/relationships/individual-types`
73+
`individuals/<number>/relationships/companies,individual-types`
74+
75+
`individual-types/<number>/individuals`
76+
`individual-types/<number>/relationships/individuals`
77+
78+
`products/<number>/companies`
79+
`products/<number>/product-types`
80+
`products/<number>/companies,product-types`
81+
82+
`products/<number>/relationships/companies`
83+
`products/<number>/relationships/product-types`
84+
`products/<number>/relationships/companies,product-types`
85+
86+
`product-types/<number>/products`
87+
`product-types/<number>/relationships/products`
88+
4489

4590

4691
#### Responses
@@ -120,93 +165,14 @@ The record always has `id` and `type` present at the top level. `id` is the uniq
120165
}
121166
```
122167

123-
`POST /login`
124-
```
125-
"username" => "niden"
126-
"password" => "110011"
127-
```
128-
129-
```json
130-
{
131-
"jsonapi": {
132-
"version": "1.0"
133-
},
134-
"data": {
135-
"token": "aa.bb.cc"
136-
},
137-
"meta": {
138-
"timestamp": "2018-06-08T15:07:35+00:00",
139-
"hash": "6219ae83afaebc08da4250c4fd23ea1b4843d"
140-
}
141-
}
142-
```
143-
144-
`GET /users/get/1051`
145-
```json
146-
{
147-
"jsonapi": {
148-
"version": "1.0"
149-
},
150-
"data": [
151-
{
152-
"id": 1051,
153-
"type": "users",
154-
"attributes": {
155-
"status": 1,
156-
"username": "niden",
157-
"issuer": "https:\/\/niden.net",
158-
"tokenPassword": "11110000",
159-
"tokenId": "11001100"
160-
}
161-
}
162-
],
163-
"meta": {
164-
"timestamp": "2018-06-08T15:07:35+00:00",
165-
"hash": "6219ae83afaebc08da4250c4fd23ea1b4843d"
166-
}
167-
}
168-
```
169-
170-
`GET /users/get`
171-
```json
172-
{
173-
"jsonapi": {
174-
"version": "1.0"
175-
},
176-
"data": [
177-
{
178-
"id": 1051,
179-
"type": "users",
180-
"attributes": {
181-
"status": 1,
182-
"username": "niden",
183-
"issuer": "https:\/\/niden.net",
184-
"tokenPassword": "11110000",
185-
"tokenId": "11001100"
186-
}
187-
},
188-
{
189-
"id": 1244,
190-
"type": "users",
191-
"attributes": {
192-
"status": 1,
193-
"username": "phalcon",
194-
"issuer": "https:\/\/phalconphp.com",
195-
"tokenPassword": "00001111",
196-
"tokenId": "99009900"
197-
}
198-
}
199-
],
200-
"meta": {
201-
"timestamp": "2018-06-08T15:07:35+00:00",
202-
"hash": "6219ae83afaebc08da4250c4fd23ea1b4843d"
203-
}
204-
}
205-
```
206-
168+
For more information regarding responses, please check [JSON API](https://jsonapi.org)
169+
207170
### TODO
208-
- Work on companies `GET`
209-
- Work on relationships and data returned
171+
- ~~Work on companies GET~~
172+
- ~~Work on relationships and data returned~~
210173
- Write examples of code to send to the client
174+
- Create docs endpoint
211175
- Work on pagination
176+
- Work on filters
177+
- Work on sorting
212178
- 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.

tests/api/Companies/GetCest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public function getCompany(ApiTester $I)
3535

3636
/**
3737
* @param ApiTester $I
38-
*
39-
* @throws \Niden\Exception\ModelException
4038
*/
4139
public function getCompanyUnknownRelationship(ApiTester $I)
4240
{

0 commit comments

Comments
 (0)