Postman collection for testing API
To run API , firstly clone my repository with API using
git clone https://github.com/BigTako/USOF-Back-End.git
. Then run commandnpm install
in cloned project root directory to install all necessary packages. Next it's required to configure a database, for that install latest version of PostgreSQL(http://postgresql.org/download/) to your computer. When it's done, use comfortable DB working program(i use https://dbeaver-io.translate.goog/?_x_tr_sl=en&_x_tr_tl=uk&_x_tr_hl=uk&_x_tr_pto=sc) and create new PostgreSQL connection. Be attentive to set DB name tousof-backed-db
and password toroot
as it's writen inconfig/db.config.js
file. If you want to change settings, just remember also to change them in config file. Finally, run commandnpm run start:dev
which will launch project in DEV mode.
NODE_ENV="development" (or "production")
PORT=3000 (or select your port)
HOST=(frontent host here, this host will handle all routes with emails, if you dont have one, just specify server http://127.0.0.1:3000/api/v1/
)
JWT_SECRET=(create some passphrase) JWT_EXPIRES_IN=90d
JWT_COOKIE_EXPIRES_IN=90
EMAIL_USERNAME=(specify email sender here) EMAIL_PASSWORD=(gmail passkey here) EMAIL_SERVICE=gmail(by default)
EMAIL_FROM=(your company)
POSThttp://127.0.0.1:3000/api/v1/auth/signup
Body parameters:
- fullName
- login
- password
- passwordConfirm
POSThttp://127.0.0.1:3000/api/v1/auth/login
Body parameters:
- password
POSThttp://127.0.0.1:3000/api/v1/auth/logout
Logout from current session
POSThttp://127.0.0.1:3000/api/v1/auth/forgotPassword
Body parameters:
- email - which account is signed up on(link will be sent there)
POSThttp://127.0.0.1:3000/api/v1/auth/resetPassword/:token
Body parameters:
- password
- passwordConfirm
Rest password to new one
GET http://127.0.0.1:3000/api/v1/users
This feature only for users with admin role
Simply returns all users data, and also you can search among them, using query.
For example:
- get user with login 'aaa123' : GET
http://localhost:3001/api/users?login=aaa123
, you can set any user field you want - sort users by createdAt field desc GET
http://localhost:3001/api/users?sort=createdAt&order=desc
- limit count of documents in responce to 4 GET
http://localhost:3001/api/users?limit=4
- receive documents from server by groups(paginate) GET
http://localhost:3001/api/users?limit=4&page=1
GEThttp://127.0.0.1:3000/api/v1/users/:id
This feature only for users with admin role
Where id is user_id
POSThttp://127.0.0.1:3000/api/v1/users
This feature only for users with admin role
Body parameters:
- profilePicture (optional)
- fullName
- login
- password
- passwordConfirm
PATCHhttp://127.0.0.1:3000/api/v1/users/:id
This feature only for users with admin role
Body parameters(all fields are optional):
- profilePicture (optional)
- fullName
- login
Password updates are not allowed here
DELETEhttp://127.0.0.1:3000/api/v1/users
This feature only for users with admin role
Delete user account(Hard delete)
GEThttp://127.0.0.1:3000/api/v1/users/rating/:id
Get rating of user by id
For authenticated users only
GEThttp://127.0.0.1:3000/api/v1/users/me
PATCHhttp://127.0.0.1:3000/api/v1/users/me
Body parameters(all fields are optional):
- profilePicture (optional)
- fullName
- login
PATCHhttp://127.0.0.1:3000/api/v1/users/updatePassword
Body parameters:
- passwordCurrent
- password
- passwordConfirm
DELETEhttp://127.0.0.1:3000/api/v1/users/me
Delete current user account(Soft delete)
GEThttp://127.0.0.1:3000/api/v1/posts/me
Get posts, published by current user (supports query selection)
GEThttp://127.0.0.1:3000/api/v1/posts/
Supports query selection fiels:
- example
http://127.0.0.1:3000/api/v1/posts/?sort=title&order=desc&limit=2&fields=id,likesCount&page=2&likesCount[gt]=-1&categories[cont]=1&title=How to use bootstrap with reactjs
Here:
- fields = use
fields
parameter to select only defined fields in each of returned documents. - sort - use
sort
parameter to sort by any field of Post modelsort=field
. - order - use
order
parameter to change order of sortingorder=asc|desc
,asc
by default. - limit - use
limit
parameter to limit the number of posts to be returned. - page - use
page
to divide returned docs into groups(size of group defined bylimit
). - Any other fields will be considered as 'filters' , you can user them by passing
field[operator]=value
. - Operators are:
[gt]
- greater than value(Number fields)[lt]
- less than value(Number fields)[gte]
- greater that or equal to value(Number fields)[lte]
- less than or equal to value(Number fields)[cont]
-field
as it Array, contains every element fromvalue
(also Array).
GEThttp://127.0.0.1:3000/api/v1/posts/:id
Where id is post_id
GEThttp://127.0.0.1:3000/api/v1/comments/post/:id
Where id is post_id
GEThttp://127.0.0.1:3000/api/v1/likes/post/:id
Where id is post_id
POSThttp://127.0.0.1:3000/api/v1/posts
You can create new post, body parameters:
- title - title of post
- content - content of post
- categories - categories of post, passing by number of category_id, you can pass one category and also array of categories, like
"categories": [1, 4]
POSThttp://127.0.0.1:3000/api/v1/likes
- type - like or dislike
- entity - can be 'post' or 'comment'(now 'post')
- entity_id - id or post wanted to be liked
Remember, to delete like from post, just create like with same type on same post twice.
POSThttp://127.0.0.1:3000/api/v1/comments
Body parameters:
- content
- entity_id:
postId
- entity: post
PATCHhttp://127.0.0.1:3000/api/v1/posts/:id
Body parameters(all are optional)
- title - title of post
- content - content of post
- categories - categories of post, passing by number of category_id, you can pass one category and also array of categories, like
"categories": [1, 4]
DELETEhttp://127.0.0.1:3000/api/v1/posts/:id
Where id is post_id
GEThttp://127.0.0.1:3000/api/v1/categories
GEThttp://127.0.0.1:3000/api/v1/categories/:id
Where id is category_id
GEThttp://127.0.0.1:3000/api/v1/posts/?categories[cont]=category
Query parameters:
- category - id of the category
POSThttp://127.0.0.1:3000/api/v1/categories
Body parameters:
- title
- description(optional)
POSThttp://127.0.0.1:3000/api/v1/categories/:id
Where id is category_id Body parameters(all are optional):
- title
- description
DELETEhttp://127.0.0.1:3000/api/v1/categories/:id
Where id is category_id
GEThttp://127.0.0.1:3000/api/v1/comments/:id
Where id is comment_id
GEThttp://localhost:3001/api/comments/:id/like
Where id is comment_id
POSThttp://127.0.0.1:3000/api/v1/likes/comment/:id
Where id is comment_id
PATCHhttp://127.0.0.1:3000/api/v1/comments/:id
Where id is comment_id Body parameters:
- status: active|unactive|locked
DELETEhttp://127.0.0.1:3000/api/v1/comments/:id
Where id is comment_id
POSThttp://127.0.0.1:3000/api/v1/likes/comment/:id
Where id is comment_id
Made by @BigTako