- NodeJS 6.9.1
- npm 3.10.9
- PostgreSQL 9.6.1
Unpack zip and enter the folder.
Install node and npm as instructed in nodejs.org:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Install PostgreSQL:
sudo apt-get install -y postgresql postgresql-contrib
Change/create password for default user
sudo -u postgres psql postgres
\password postgres
\q
Create database schema
sudo -u postgres psql < schema.sql
Create config file based on config/example.json
and save it as config/default.json
Generate self-signed certificate for HTTPS
cd ssl
openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
cd ..
Install dependencies
npm install
(When running from port 443 sudo is required)
npm start
Run tests
npm test
Install pm2
sudo npm install -g pm2
Run
pm2 start process.json
Follow the instructions from this command
pm2 startup ubuntu
POST /client/
Payload must be object, key value based and must contain email
and phone
key-value pairs.
{
"name": "jason born",
"email": "iwasbornjason@example.com",
"phone": "77 1234 5678",
"age": 44,
"alive": true
}
Returns HTTP status 201 and location header on success, JSON data and status code 400 on error.
GET /client/<id>
Id parameter must be number.
Returns HTTP status 200 and client data as JSON on success, status code 404 if client is not found.
{
"name": "jason born",
"email": "iwasbornjason@example.com",
"phone": "*********5678",
"age": 44,
"alive": "true"
}
GET /client/
Returns JSON object with client ids as keys and client data as values.
{
"1": {
"email": "kris@hallaine.net",
"phone": "*********2852",
"tere": "piim",
"alma": 123
},
"2": {
"email": "kris@hallaine.net",
"phone": "*********2852",
"tere": "piim",
"alma": 123
},
"3": {
"email": "kris@hallaine.net",
"phone": "*********2852",
"tere": "piim",
"alma": 123,
"textas": "{1,2,0}"
}
}
GET /client/?<key>=<value>
Key and value must both be strings. Only supports searching by 1 pair.
Returns HTTP status 200 and clients matching search data.
{
"184": {
"name": "jason born",
"email": "iwasbornjason@example.com",
"phone": "*********5678",
"age": 44,
"alive": "true"
}
}
Kristian Saarela kristian.saarela(ät)eesti.ee