Skip to content

πŸ”’ Api for requesting users login, register, authenticaton, user data, update profiles, for client angular chat application

Notifications You must be signed in to change notification settings

Gabrieldev-web-coder/chat-app-api-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chat api

This is a relatively simple rest api for made basic operations on database for my chat app application builded in Angular, also for learning propuses, wrote it 100% with TypeScript and NodeJs, is be able to register, login, send friend request and response them, search users, change user profile settings, manage friend list, (And soon manage groups).

Finding users

  • URL

    /chat-api/v1.0/user?id=user-id

  • Method:

    GET

  • URL Params

    Simple method for get basic user information that has been registered before by id.

    Required:

    id=[integer]

  • Success Response:

    On success response will return a simple json containing basic information of user, should looks like following.

    • Code: 200
      Content:
      {
        "email": "example@gmail.com",
        "username": "example",
        "userid": 0002,
        "picurl": "https://svgsilh.com/svg/1699635.svg",
        "country": "ec",
        "description": "Hi! i'm example, nice to meet you! :D"
      }
  • Error Response:

    If for some reason user's id that was provided not exist just will return a simple body with errors fields as follow.

    • Code: 404 NOT FOUND
      Content:
      { "errors": "This user don't exist." }
  • Sample Call:

    /chat-api/v1.0/user?id=0001

Login users

  • URL

    /chat-api/v1.0/login-user

  • Method:

    POST

  • Data Params

    Using a basic authentication using username or email to identify user and a password for server validation.

    Payload:

{
  "username": "example",
  "pwd": "examplePwd"
}
  • Success Response:

    On success response will return a json with complete user's information, should looks as follow.

    • Code: 200
      Content:
{
  "email": "example@hotmail.com",
  "username": "example",
  "userid": 0001,
  "picurl": "https://svgsilh.com/svg/1699635.svg",
  "country": "ec",
  "accountCreatedAt": "Thursday, August 11, 2022 9:47 AM",
  "description": "Hi! i'm example, nice to meet you! :D",
  "lastMoficationAt": "No changes yet.",
  "groups": [],
  "friends": [],
  "pendingRequest": [
    {
      "to": 9998,
      "accepted": null
    }
  ],
  "friendRequest": [
    {
      "from": 9991,
      "accepted": null
    }
  ],
  "token": "token."
}
  • Error Response:

    Depending type of error, will return a json with a "errors" field saying what's wrong with request.

    • Code: 500 INTERNAL SERVER ERROR
      Content:

      { "errors": "Incorrect password." }
      //OR
      { "errors": "This user don't exist, consider register" }
      
  • Sample Call:

    /chat-api/v1.0/login-user

Register users

  • URL

    /chat-api/v1.0/register-user

  • Method:

    POST

  • Data Params

    Here must send an email, username and password as body payload to confirm a new user registered.

    Payload:

{
  "email": "example@hotmail.com",
  "username": "exampleUser",
  "pwd": "1234567890"
}
  • Success Response:

    On success response will return a jwt to session initialization, should looks as follow.

    • Code: 200
      Content:
{ "token": "token." }
  • Error Response:

    Depending type of error, will return a json with a "errors" field saying what's wrong with request.

    • Code: 500 INTERNAL SERVER ERROR
      Content:
{ "errors": "Your username or email is already taken." }
  • Sample Call:

    /chat-api/v1.0/register-user

Update users

  • URL

    /chat-api/v1.0/update-user

  • Method:

    PUT

  • Data Params

    Payload of this route consist in the fields the user want change, with the new value to replace it.

    Optional fields:

{
  "email": "newExample@hotmail.com",
  "username": "newExampleUser",
  "picurl": "newPic",
  "country": "newLocation",
  "description": "newDescription"
}

Required fields:

{
  "token": "token"
}
  • Success Response:

    On success response will return a message field with a message field and a boolean value if update was made sucessfully.

    • Code: 200
      Content:
{ "message": true }
  • Error Response:

    At this request can went wrong token body, by signature, expired, or invalid values, body should looks like follow.

    • Code: 401 Unauthorized
      Content:
{
  "message": "No authorized",
  "errors": [
    {
      "value": "given token",
      "msg": "invalid signature",
      "param": "token",
      "location": "body"
    }
  ]
}
  • Sample Call:

    /chat-api/v1.0/update-user