/tmessage-api

Restful API for tmessage - a CLI based messaging tool (https://github.com/Haider8/tmessage)

Primary LanguageJavaScript

tmessage API

This is a RESTful API handling authentication logic for tmessage - a lightweight and low bandwidth chatting tool.

Installation and Hosting

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:

  1. Open the terminal where you want to store the project
  2. Clone the project:
    git clone https://github.com/Haider8/tmessage-api.git
  3. Navigate into the project:
    cd tmessage-api
  4. Install all dependencies/packages of the project:
    npm i
  5. Create a file named .env in the current directory:
    touch .env
  6. Open the .env file with a text editor and enter the following content:
    MONGODB_CONNECTION_STRING=[Your MongoDB connection string]
    
  7. Subtitute [Your MongoDB connection string] with your MongoDB connection string you got earlier.
  8. Save and close the file.
  9. Host the API:
    node server.js
  10. Use an Http Client (e.g.: Postman) to test the API.

API References

POST: /api/user/register

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 is true, undefined otherwise
  • message: A message

POST: /api/user/login

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 is true, undefined otherwise
  • message: A message

GET: /api/user/checkExist/:user_name

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 the user_name is occupied, false if the user_name is not taken, undefined if success is false
  • message: A message