https://github.com/shubhambansal1997/attainu-api
Attain U test api endpoints
https://github.com/shubhambansal1997/attainu-api
Last synced: 4 months ago
JSON representation
Attain U test api endpoints
- Host: GitHub
- URL: https://github.com/shubhambansal1997/attainu-api
- Owner: ShubhamBansal1997
- Created: 2020-11-08T14:11:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-08T14:12:17.000Z (over 4 years ago)
- Last Synced: 2025-01-04T20:46:32.306Z (5 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AttainU assignment
Backend project for the attainu
---
## RequirementsFor development, you will only need Node.js and a node global package, npm, installed in your environement.
### Node
- #### Node installation on WindowsJust go on [official Node.js website](https://nodejs.org/) and download the installer.
Also, be sure to have `git` available in your PATH, `npm` might need it (You can find git [here](https://git-scm.com/)).- #### Node installation on Ubuntu
You can install nodejs and npm easily with apt install, just run the following commands.
$ sudo apt install nodejs
$ sudo apt install npm- #### Other Operating Systems
You can find more information about the installation on the [official Node.js website](https://nodejs.org/) and the [official NPM website](https://npmjs.org/).If the installation was successful, you should be able to run the following command.
$ node --version
v12.18.1$ npm --version
6.14.5If you need to update `npm`, you can make it using `npm`! Cool right? After running the following command, just open again the command line and be happy.
$ npm install npm -g
---## Install
$ git clone https://github.com/ShubhamBansal1997/attainu
$ cd attainu
$ npm install
$ cp .env.sample .env## Configure app
Open `.env` then edit it with your settings. You will need:
- Mongodb Connection String;
- JWT Secert Key;
- http port;## Running the project
$ npm start
# API endpoints
!!!info
For API overview and usages.## Create User
```
POST /users
```__Parameters__
Name | Description
---------|-------------------------------------
name | name of the user.
address | address of the user.
email | email of the user.
password | password of the user.__Request__
```json
{
"name": "Test User",
"address": "Test Address",
"email": "[email protected]",
"password": "VerySafePassword0909"
}
```__Response__
```jsonStatus: 201 Created
{
"user": {
"_id": "5fa7ef03cda7735c6ea02d56",
"name": "Test User",
"address": "Test Address",
"email": "[email protected]",
"password": "$2a$10$Lv9Vt9mKerZ1zulDUFdpuuwk.EeeAV1ia6YuqdV7a8pLASOStycL2",
"tokens": [
{
"_id": "5fa7ef03cda7735c6ea02d57",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmE3ZWYwM2NkYTc3MzVjNmVhMDJkNTYiLCJpYXQiOjE2MDQ4NDEyMTl9.BPem_07pRrYLj_PiHl554C0K8JGgVe1qipo-CrAJTIY"
}
],
"__v": 1
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmE3ZWYwM2NkYTc3MzVjNmVhMDJkNTYiLCJpYXQiOjE2MDQ4NDEyMTl9.BPem_07pRrYLj_PiHl554C0K8JGgVe1qipo-CrAJTIY"
}
```## Login
```
POST /users/login
```__Parameters__
| Name | Description |
| ---------- | ---------------------------------------------------------- |
| email | email of the user. Errors out if email already registered. |
| password | password of the user. |**Request**
```json
{
"email": "[email protected]",
"password": "VerySafePassword0909"
}
```__Response__
```json
Status: 200 Ok
{
"user": {
"_id": "5fa7ef03cda7735c6ea02d56",
"name": "Test User",
"address": "Test Address",
"email": "[email protected]",
"password": "$2a$10$Lv9Vt9mKerZ1zulDUFdpuuwk.EeeAV1ia6YuqdV7a8pLASOStycL2",
"tokens": [
{
"_id": "5fa7ef03cda7735c6ea02d57",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmE3ZWYwM2NkYTc3MzVjNmVhMDJkNTYiLCJpYXQiOjE2MDQ4NDEyMTl9.BPem_07pRrYLj_PiHl554C0K8JGgVe1qipo-CrAJTIY"
},
{
"_id": "5fa7ef6bcda7735c6ea02d58",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmE3ZWYwM2NkYTc3MzVjNmVhMDJkNTYiLCJpYXQiOjE2MDQ4NDEzMjN9.qhlYwW7QNCEEiRaElDU5iswDomw3aQXccPuUJ69KdYA"
}
],
"__v": 2
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmE3ZWYwM2NkYTc3MzVjNmVhMDJkNTYiLCJpYXQiOjE2MDQ4NDEzMjN9.qhlYwW7QNCEEiRaElDU5iswDomw3aQXccPuUJ69KdYA"
}
```## Get profile
```
GET /users/me (requires authentication)
```__Response__
```
Status: 200 Ok
{
"_id": "5fa7ef03cda7735c6ea02d56",
"name": "Test User",
"address": "Test Address",
"email": "[email protected]",
"password": "$2a$10$Lv9Vt9mKerZ1zulDUFdpuuwk.EeeAV1ia6YuqdV7a8pLASOStycL2",
"tokens": [
{
"_id": "5fa7ef03cda7735c6ea02d57",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmE3ZWYwM2NkYTc3MzVjNmVhMDJkNTYiLCJpYXQiOjE2MDQ4NDEyMTl9.BPem_07pRrYLj_PiHl554C0K8JGgVe1qipo-CrAJTIY"
},
{
"_id": "5fa7ef6bcda7735c6ea02d58",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmE3ZWYwM2NkYTc3MzVjNmVhMDJkNTYiLCJpYXQiOjE2MDQ4NDEzMjN9.qhlYwW7QNCEEiRaElDU5iswDomw3aQXccPuUJ69KdYA"
}
],
"__v": 2
}
```## Logout User from a single device
```
GET /users/me/logout (requires authentication)
```__Response__
```json
Status: 204 No-Content
```## Logout User from all device(s)
```
GET /users/me/logoutall (requires authentication)
```__Response__
```json
Status: 204 No-Content
```## Update User details(name, email, address)
```
PATCH /users/{user_id} (requires authentication)
```__Parameters__
Name | Description
---------|-------------------------------------
name | name of the user.
address | address of the user.
email | email of the user.__Request__
```json
{
"name": "Test User",
"address": "Test Address",
"email": "[email protected]"
}
```__Response__
```
Status: 204 No-Content
```## Resize the image to thumbnail (50 x 50)
```
POST /users/thumbnail (requires authentication)
```__Parameters__
Name | Description
---------|-------------------------------------
uri | url of the image.__Request__
```json
{
"uri": "https://i.pinimg.com/originals/ca/76/0b/ca760b70976b52578da88e06973af542.jpg"
}
```__Response__
```
Status: 201 Created
{
"output": "images/f9785bcf-3f3d-45d9-9291-81d8bcab7e60.png"
}
```