This is a RESTful API handling authentication logic for tmessage - a lightweight and low bandwidth chatting tool.
First, to host this API locally, you would need...
- Node.js and NPM (Noed Package Manager) installed
- A text editor
- A command-line terminal
Second, you would need to host a MongoDB database. You can either do it locally or on a service such as mongoDB Atlas. When the database is up and running, you need a connection string to set up connection between the API and the database (follow this instruction if you use mongoDB Atlas).
Step-by-step to set up the API:
- Open the terminal where you want to store the project
- Clone the project:
git clone https://github.com/Haider8/tmessage-api.git
- Navigate into the project:
cd tmessage-api
- Install all dependencies/packages of the project:
npm i
- Create a file named
.env
in the current directory:touch .env
- Open the
.env
file with a text editor and enter the following content:MONGODB_CONNECTION_STRING=[Your MongoDB connection string]
- Subtitute
[Your MongoDB connection string]
with your MongoDB connection string you got earlier. - Save and close the file.
- Host the API:
node server.js
- Use an Http Client (e.g.: Postman) to test the API.
Make a reuqest to this route to register a User Account, expected body data shape:
- user_name: A string - name used for login (used with the --user parameter)
- displayed_name: A string - name used to display when communicate with others
- password: A string
- password_confirm: A string matches
password
The reponse of returned data includes 2 fields:
- success:
true
if the registration process is successfull,false
otherwise - token: A JWT token to be decoded if
success
istrue
,undefined
otherwise - message: A message
Make a reuqest to this route to login, expected body data shape:
- user_name: A string
- password: A string
The reponse of returned data includes 2 fields:
- success:
true
if the login process is successfull,false
otherwise - token: A JWT token to be decoded if
success
istrue
,undefined
otherwise - message: A message
Make a request to this route to check if a user_name
is occupied or not.
The reponse of returned data includes 3 fields:
- success:
true
if the checking process is successfull,false
otherwise - exist:
true
if theuser_name
is occupied,false
if theuser_name
is not taken,undefined
ifsuccess
isfalse
- message: A message