Backend Task
Budget: ₹1,750 – ₹2,250 INR
## 1. Create an app with Node.JS
#### The API should support the following
- User Signup
- Users Sign-In
- Allow user to access their own information
A `user` must have the following information:
- username
- password (Please hash the passwords, you may use MD5/SHA-2 etc)
- firstname
- lastname
**Please do not use a database to store the User information, store it in a JSON file stored on the local file system. (No MongoDB, No MySQL, No Postgres, No Elasticsearch, No Sqlite) -- Plain old JSON.**
#### Data Validation
#### Some data validations that should be taken care of
- username
- can only contain lowercase English alphabets (no numbers and special characters) [example: `pointmotion` is allowed, `PointMotion` is not allowed, `PointMotion1` is not allowed, `Point@Motion` is not allowed]
- it should be of at least 4 characters
- password
- must contain at least 1 uppercase character
- must contain at least 1 lowercase character
- must contain at least 1 number
- no special characters allowed
- should be of at least 5 characters
- fname
- First name
- should only contain English alphabets [A-Z, a-z]
- lname
- Last name
- should only contain English alphabets [A-Z, a-z]
### (Requests / Responses)
#### - POST /signup
- The request body should have `username`, `fname`, `lname` and `password`
- The body should be content-type application/json
```
{
"username": "<username>",
"password": "<password>",
"fname": "<first_name>",
"lname": "<last_name>"
}
```
On success, this should return with HTTP status code 201
```
{
"result": true,
"message": "SignUp success. Please proceed to Signin"
}
```
On failure, either due to empty body, field constraints or missing fields, please check the provided Postman collection.
#### - POST /signin
- The request body should have `username` and `password`
- The body should be application/json
- On successful login, you have to sign a JWT token with the `username` and `firstname` in the JWT payload.
```
{
"username": "<username>",
"password": "<password>"
}
```
On success, this should return with HTTP status code 200
```
{
"result": true,
"jwt": "<jwt_token>",
"message": "Signin success"
}
```
On failure, either due to empty body, invalid credentials or missing fields, please check the provided Postman collection.
#### - GET /user/me
- Set the Authorization header equal to JWT token you received after POST /signin
On success, this should return with HTTP status code 200
```
{
"result": true,
"data": {
"fname": "<first_name>",
"lname": "<last_name>",
"password": "<hashed_password>" // bad practice, doing it just for the task
}
}
```
On failure, in case of missing token, it should return with HTTP status code 400
```
{
"result": false,
"error": "Please provide a JWT token"
}
```
On failure, in case of bad token, it should return with HTTP status code 400
```
{
"result": false,
"error": "JWT Verification Failed"
}
```
## 2. Testing your server
You will need to [Download Postman](https://www.postman.com/downloads/) to test your server.
Your code will be evaluated against a postman collection which you can [download here](assets/postman/collection.json).
The postman collection consists of the tests already written for you. You just have to run all the cases against your application and see if they all pass (green ticks).
You will have to set a few variable names in the Postman collection to run the test cases effectively. ([Here is a video to help understand Postman variables better](https://www.youtube.com/watch?v=ENNsL-XGLus))
#### The API should support the following
- User Signup
- Users Sign-In
- Allow user to access their own information
A `user` must have the following information:
- username
- password (Please hash the passwords, you may use MD5/SHA-2 etc)
- firstname
- lastname
**Please do not use a database to store the User information, store it in a JSON file stored on the local file system. (No MongoDB, No MySQL, No Postgres, No Elasticsearch, No Sqlite) -- Plain old JSON.**
#### Data Validation
#### Some data validations that should be taken care of
- username
- can only contain lowercase English alphabets (no numbers and special characters) [example: `pointmotion` is allowed, `PointMotion` is not allowed, `PointMotion1` is not allowed, `Point@Motion` is not allowed]
- it should be of at least 4 characters
- password
- must contain at least 1 uppercase character
- must contain at least 1 lowercase character
- must contain at least 1 number
- no special characters allowed
- should be of at least 5 characters
- fname
- First name
- should only contain English alphabets [A-Z, a-z]
- lname
- Last name
- should only contain English alphabets [A-Z, a-z]
### (Requests / Responses)
#### - POST /signup
- The request body should have `username`, `fname`, `lname` and `password`
- The body should be content-type application/json
```
{
"username": "<username>",
"password": "<password>",
"fname": "<first_name>",
"lname": "<last_name>"
}
```
On success, this should return with HTTP status code 201
```
{
"result": true,
"message": "SignUp success. Please proceed to Signin"
}
```
On failure, either due to empty body, field constraints or missing fields, please check the provided Postman collection.
#### - POST /signin
- The request body should have `username` and `password`
- The body should be application/json
- On successful login, you have to sign a JWT token with the `username` and `firstname` in the JWT payload.
```
{
"username": "<username>",
"password": "<password>"
}
```
On success, this should return with HTTP status code 200
```
{
"result": true,
"jwt": "<jwt_token>",
"message": "Signin success"
}
```
On failure, either due to empty body, invalid credentials or missing fields, please check the provided Postman collection.
#### - GET /user/me
- Set the Authorization header equal to JWT token you received after POST /signin
On success, this should return with HTTP status code 200
```
{
"result": true,
"data": {
"fname": "<first_name>",
"lname": "<last_name>",
"password": "<hashed_password>" // bad practice, doing it just for the task
}
}
```
On failure, in case of missing token, it should return with HTTP status code 400
```
{
"result": false,
"error": "Please provide a JWT token"
}
```
On failure, in case of bad token, it should return with HTTP status code 400
```
{
"result": false,
"error": "JWT Verification Failed"
}
```
## 2. Testing your server
You will need to [Download Postman](https://www.postman.com/downloads/) to test your server.
Your code will be evaluated against a postman collection which you can [download here](assets/postman/collection.json).
The postman collection consists of the tests already written for you. You just have to run all the cases against your application and see if they all pass (green ticks).
You will have to set a few variable names in the Postman collection to run the test cases effectively. ([Here is a video to help understand Postman variables better](https://www.youtube.com/watch?v=ENNsL-XGLus))
Related categories:
Business, Accounting, Human Resources & Legal
NoSQL Couch & Mongo
MySQL
Node.js
JSON