Before run application need to install the latest version of Node.js.
First need to change the configuration files for server. Configuration files already into ./config
directory. Configuration files are available for each NODE_ENV
separately. They also extend from the default.js
file.
config
├── default.js
├── development.js
├── production.js
└── staging.js
Documentation: https://github.com/lorenwest/node-config/wiki
Key | Description | Default |
---|---|---|
NODE_ENV | Env for run application | development |
API_PORT | Port for application | 5000 |
DB_HOST | Host for PostgreSQL server | 127.0.0.1 |
DB_NAME | Name for database | tt_db |
DB_USER | User name for PostgreSQL | tt_user |
DB_PASSWORD | Password name for PostgreSQL | tt_password |
Before run need to install dependencies, migrations and seeds.
npm i
npm run migration
npm run seed
Run with debugger:
npm run dev
Run for staging/production:
npm run start
Response:
{
"status": true,
"result": [
{
"id": 1,
"name": "Russia",
"created_at": "2019-02-13T07:51:59.732Z",
"updated_at": "2019-02-13T07:51:59.732Z"
}
]
}
Response:
{
"status": true,
"result": {
"country": {
"id": 1,
"name": "Russia",
"created_at": "2019-02-13T07:51:59.732Z",
"updated_at": "2019-02-13T07:51:59.732Z"
},
"teams": [
{
"id": 2,
"name": "CSKA Moscow",
"created_at": "2019-02-13T07:51:59.739Z",
"updated_at": "2019-02-13T07:51:59.739Z"
}
]
}
}
Country Creation Method.
Payload description:
Key | Description | Is Required? |
---|---|---|
name | Name of country | yes |
Request:
curl -X POST \
http://localhost:5000/countries/create \
-H 'Content-Type: application/json' \
-d '{"name": "Turkey"}'
Response (success):
{
"status": true
}
Response (error):
{
"status": false,
"error": "validation error child \"name\" fails because [\"name\" is required]"
}
Country Update Method.
Payload description:
Key | Description | Is Required? |
---|---|---|
id | Item ID | yes |
name | Name of country | yes |
Request:
curl -X PUT \
http://localhost:5000/counntries/update \
-H 'Content-Type: application/json' \
-d '{"id": 9, "name": "Egypt"}'
Response (success):
{
"status": true
}
Response (error):
{
"status": false,
"error": "validation error child \"id\" fails because [\"id\" is required]. child \"name\" fails because [\"name\" is required]"
}
Country Delete Method.
Payload description:
Key | Description | Is Required? |
---|---|---|
id | Item ID | yes |
Request:
curl -X DELETE \
http://localhost:5000/teams/delete \
-H 'Content-Type: application/json' \
-d '{"id": 3}'
Response (success):
{
"status": true
}
Response (error):
{
"status": false,
"error": "validation error child \"id\" fails because [\"id\" is required]"
}
Response:
{
"status": true,
"result": [
{
"id": 1,
"country": "Russia",
"country_id": 1,
"name": "Spartak Moscow",
"created_at": "2019-02-13T07:51:59.739Z",
"updated_at": "2019-02-13T07:51:59.739Z"
},
]
}
Response:
{
"status": true,
"result": {
"id": 1,
"country": "Russia",
"country_id": 1,
"name": "Spartak Moscow",
"created_at": "2019-02-13T07:51:59.739Z",
"updated_at": "2019-02-13T07:51:59.739Z"
}
}
Team Creation Method.
Payload description:
Key | Description | Is Required? |
---|---|---|
name | Name of team | yes |
country | Country ID | yes |
Request:
curl -X POST \
http://localhost:5000/teams/create \
-H 'Content-Type: application/json' \
-d '{"name": "FC Bishkek", "country": 3}'
Response (success):
{
"status": true
}
Response (error):
{
"status": false,
"error": "validation error child \"country\" fails because [\"country\" is required]. child \"name\" fails because [\"name\" is required]"
}
Teams Update Method.
Payload description:
Key | Description | Is Required? |
---|---|---|
id | Item ID | yes |
name | Name of country | yes |
country | Country ID | yes |
Request:
curl -X PUT \
http://localhost:5000/teams/update \
-H 'Content-Type: application/json' \
-d '{"name": "FC Egypt", "id": 9, "country": 3}'
Response (success):
{
"status": true
}
Response (error):
{
"status": false,
"error": "validation error child \"id\" fails because [\"id\" is required]. child \"name\" fails because [\"name\" is required]"
}
Teams Delete Method.
Payload description:
Key | Description | Is Required? |
---|---|---|
id | Item ID | yes |
Request:
curl -X DELETE \
http://localhost:5000/teams/delete \
-H 'Content-Type: application/json' \
-d '{"id": 3}'
Response (success):
{
"status": true
}
Response (error):
{
"status": false,
"error": "validation error child \"id\" fails because [\"id\" is required]"
}