Requirements
Next modules should be installed globally:
nodejs
^8.xnpm
^6.xknex
^0.15.xtypescript
^3.xpostgres
^10.x
Deployment
- Create manually some DB.
- Write connection settings to
config.json
in the root of project. - Execute in terminal:
npm i
tsc
npm run latest
npm run seed # optional
npm run start
Another commands for using with npm
you can see in package.json
in the root of project.
SERVER API
id
Getting users by Request:
curl -X GET http://HOST:3000/users/ID
Where:
HOST
is thedb.host
parameter fromconfig.json
;ID
is user ID.
Example:
curl -X GET http://127.0.0.1:3000/users/2
Response:
It will be an JS object:
- empty if user doesn't exist by ID;
- data about found user.
Example:
{
"id": "2",
"email": "cap@avengers.com",
"first_name": "Kris",
"last_name": "Evans",
"created_at": "2018-11-27T10:21:20.270Z",
"updated_at": "2018-11-27T10:21:20.270Z"
}
Inserting and updating user
Request:
If you need to update user by id
you should send id
parameter in request body:
curl -X POST \
http://HOST:3000/users \
-H 'content-type: application/json' \
-d '{
"id": ID_VALUE,
...
}'
Or without id
parameter if you need to create new user.
Example:
curl -X POST \
http://127.0.0.1:3000/users \
-H 'content-type: application/json' \
-d '{
"id": 3,
"email": "test1@example.com",
"first_name": "test1_firstname",
"last_name": "test1_lastname"
}'
Response:
Created or updated user with new values, or empty JS object if user wasn't found by id
:
{
"id": "3",
"email": "test1@example.com",
"first_name": "test1_firstname",
"last_name": "test1_lastname"
"created_at": "2018-11-27T10:21:25.447Z",
"updated_at": "2018-11-27T11:11:19.928Z"
}