This simple application have three basic entities:
- Customers
- Executors
- Tasks
Customer can place a task into Market and set a price. Executor can execute a task for a given price. Market gets it's fee. Entities are stored in different databases.
All responses are json objects or empty objects.
| Route | Method | Parameters | Reply | Errors | Description |
|---|---|---|---|---|---|
/customers |
GET | offset=<int>, length=<int> | List of customers |
|
Returns list of customers with paging |
/customers |
POST | balance=<int> | Customer object |
|
Returns new customer object with one's id |
/customers/{id} |
GET | Customer object |
|
Returns existing customer by one's id | |
/customers/{id} |
PUT | balance=<int> | Customer object |
|
Updates customer balance |
/customers/{id} |
DELETE |
|
Delete customer with all one's tasks | ||
/customers/{id}/tasks |
POST | value=<int> | Task object |
|
Creates new task with a given value |
/executors |
GET | offset=<int>, length=<int> | List of executors |
|
Returns list of executors with paging |
/executors |
POST | balance=<int> | Executor object |
|
Returns new executor object with one's id |
/executors/{id} |
GET | Executor object |
|
Returns existing executor by one's id | |
/executors/{id} |
DELETE |
|
Delete executor | ||
/executors/{id}/tasks/{id} |
POST |
Customer balance is too low. |
Transfers money from to executor. Executor pays fee. Task is deleted. | ||
/tasks |
GET | length=<int>, offset=<int> | List of tasks |
|
Returns list of tasks with paging |
Customer:
{
"id": <int>,
"balance: <int>
}
Executor:
{
"id": <int>,
"balance: <int>
}
Task:
{
"id": <int>,
"value": <int>,
"customer": <int>
}
> php -S localhost:8000 router.php
Create new customer
$ curl -X POST 'localhost:8000/customers?balance=1000'
{"id":1,"balance":1000}
List customers
$ curl 'localhost:8000/customers'
{"users":[{"id":"1","balance":"1000"}]}
Update customer balance
$ curl -X PUT 'localhost:8000/customers/1?balance=5000'
{"id":"1","balance":5000}
Create new executor
$ curl -X POST 'localhost:8000/executors'
{"id":1,"balance":0}
Create new task
$ curl -X POST 'localhost:8000/customers/1/tasks?value=10'
{"id":1,"value":10,"customerId":"1"}
Execute task
$ curl -X POST 'localhost:8000/executors/1/tasks/1'
$ curl 'localhost:8000/customers'
{"users":[{"id":"1","balance":"4990"}]}
$ curl 'localhost:8000/executors/1'
{"id":"1","balance":5}