Second-hand goods market API.
API has next endpoints:
- register
- auth
- tags
- advertisements
After project cloning and installing dependencies, you have to run server by:
npm start
.
In development environment doesn't use cluster mode.
In production environment, use only builded package. You need to installed pm2 in your work environment and run pm2 start index.js -i 0
script. It will start server in cluster mode, using available CPUs.
MongoDB shell version must be >= 3.4.2
Go to scripts/database/mongodb/
directory and execute there the command mongo install_bd.js
.
System has feature to humanize error messages, there is hardcoded default messages model, it uses if no-one translation found. If error is not described anywhere, it has format region:type
.
External document located at assets/docs/errorMessages.json
, which has strict structure to translate errors relatively to language. If defined language at user
or at query is absent, system uses en
as default.
Here is something special to know: messages are support template literals. I.e.:
Email (${email}) or password (${passwd}) are wrong.
, where ${key} - is passed value through error.
Request examples in curl.
Query:
- lang: error message language priority
- token: for
adverts
request
curl -XPOST http://localhost:3000/apiv1/register?lang=es -H 'Content-Type: application/json' -d '{ "name": "dimpiax", "email": "dimpiax@gmail.com", "passwd": "root", "lang": "UA" }'
Returns AUTH_TOKEN
curl -XPOST http://localhost:3000/apiv1/auth -H 'Content-Type: application/json' -d '{ "email": "dimpiax@gmail.com", "passwd": "root" }'
curl -XGET http://localhost:3000/apiv1/adverts/tags?lang=es\&token=AUTH_TOKEN
Query has additional keys:
Documents includes in response that satisfy conditions:
- name (string): starts by given string
- price (string | double): partly or whole range for
price
property - toSell (boolean): advertisement type
- tag (string): value that exist in
tags
array property - limit (number): limit documents count in response
- start (number): show page relatively to limit count. I.e.: start is 5 and limit is 10, documents will be shown from 50 index.
Documents can be sorted:
- sort (string): ascending sorting by set specific property
- paging, sorting, price interval, tag
curl -XGET http://localhost:3000/apiv1/adverts?token=AUTH_TOKEN\&start=0\&limit=2\&sort=toSell\&price=10-230.15\&tag=motor
- advertisement type
curl -XGET http://localhost:3000/apiv1/adverts?token=AUTH_TOKEN\&toSell=false
Project implemented on JavaScript, using the latest ES features, dated on the latest commit.
Its development environment based on: Babel, Flow, ESLint.