Git repository for laboradmin backend service
You will need the following things properly installed on your computer.
- Git
- Node.js (8.x)
- PostgreSQL
Clone repository
git clone <repository-url>
Install npm packages
cd szglab5-backend
npm install
Install nodemon (automatic server restart)
npm install nodemon -g
Create database (default is "laboradmin")
psql -U postgres
CREATE DATABASE laboradmin;
Available node environments ('dev' | 'prod' | 'test')
Steps to add specific config:
- Create a new file to config/ with name of config.[env].json
- Copy the content of config.example.json to the new file
- Modify or delete rows
- filepath: the json file path that contains the seed data, relative to /db/seedData (default: 'dev.seed.json')
npm run cli:dev seed test1.seed.json
Starts the API server
npm run start:dev
The endpoints format fit JSON API specification.
Model names in plural (-> modelNamePlural):
- tests (Test model)
- languages (Language model)
- questions (Question model)
- Request: GET /questions HTTP/1.1
- Response:
{
"data": [
{
"type": "questions",
"id": 4,
"attributes": {
"id": 4,
"text": "tuturu 2",
"createdAt": "2017-03-15T17:07:30.284Z",
"updatedAt": "2017-03-15T17:07:30.284Z",
"testId": 2
},
"relationships": {
"test": {
"data": {
"id": 2,
"type": "tests"
}
}
}
},
{
"type": "questions",
"id": 1,
"attributes": {
"id": 1,
"text": "Kérdés 1",
"createdAt": "2017-03-15T17:07:30.244Z",
"updatedAt": "2017-03-15T17:07:30.244Z",
"testId": null
},
"relationships": {
"test": null
}
},
{
"type": "questions",
"id": 2,
"attributes": {
"id": 2,
"text": "Kérdés 2",
"createdAt": "2017-03-15T17:07:30.261Z",
"updatedAt": "2017-03-15T17:07:30.261Z",
"testId": null
},
"relationships": {
"test": null
}
}
]
}
- Request: GET /questions/2 HTTP/1.1
- Response:
{
"data": {
"type": "questions",
"id": 2,
"attributes": {
"id": 2,
"text": "Kérdés 2",
"createdAt": "2017-03-15T17:07:30.261Z",
"updatedAt": "2017-03-15T17:07:30.261Z",
"testId": null
},
"relationships": {
"test": null
}
}
}
!Not supported yet!
- Header: Content-Type: application/vnd.api+json
- Request: POST /questions
- Body:
{
"data": {
"type": "questions",
"attributes": {
"text": "New questiion, yupiii blblblblblb"
},
"relationships": {
"test": {
"data": {
"type": "tests",
"id": 3
}
}
}
}
}
Response:
{
"data": {
"type": "questions",
"id": 8,
"attributes": {
"id": 8,
"text": "New questiion, yupiii blblblblblb",
"updatedAt": "2017-03-16T09:12:29.966Z",
"createdAt": "2017-03-16T09:12:29.956Z",
"testId": 3
}
}
}
- Header: Content-Type: application/vnd.api+json
- Request: PATCH /questions/2
- Body:
{
"data": {
"type": "questions",
"attributes": {
"text": "Change this text!"
},
"relationships": {
"test": {
"data": {
"type": "tests",
"id": 3
}
}
}
}
}
Response: 204 (No Content)
- Request: DELETE /questions/2
- Response: 204 (No Content)