Coder Social home page Coder Social logo

raferdev / batepapo-uol-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 168 KB

One simple backend API to serve frontend online chat. Use NodeJS, Express, JOI, MongoDB and more.

License: MIT License

JavaScript 98.06% Dockerfile 1.94%
bate-papo chat express joi mongodb nodejs chatroom

batepapo-uol-api's Introduction

Project logo

Bate Papo UOL API

Status GitHub Issues GitHub Pull Requests License


This is a backend project without complex architeture, its created to serve the frontend project which you can see here, and its a pratice into express world using middlewares, JOI to verify schemas and more.


๐Ÿ“ Table of Contents


๐Ÿง About

This project is used to generate one simple online chat, which store participants, messages and logs. It's serve the frontend and can verify the body of requests to maintain the business rules.


๐Ÿ Getting Started

You can clone the project and start on your local host like below.

Prerequisites

You need install GIT if you don't already have, to clone project,.

Click here or Acess:

https://git-scm.com/downloads

You need install Docker on your machine if you don't already have.

Click here or Acess:

https://docs.docker.com/get-docker/

And use the step-by-step doc to download and install on your specific system.

Installing

1 - Clone on your local system

git clone https://github.com/raferdev/batepapo-uol-api

2 - Go to project path

cd batepapo-uol-api

3 - Create env file

You can rename the ".env.exemple" file to ".env", just removing ".exemple" and save, or follow this steps to create new one:

  • Open a text editor or other editor do you prefeer, create this variables like below and save file with name '.env'.
MONGO_URI=mongodb://mongodb:27017/
PORT_HOST=5000

You can change the values of variables if you want or need.

Start

Use on terminal:

npm run start

The attached console will show "Hello i'm running on port = (PORT)" and after some mongodb logs.


๐ŸŽˆ Usage

Now you will need one tool to make requests and interact whith your API. Some famous API Clients are Insomnia, Thunder CLient to VSCode users, Postman and many others, like browsers plugins. If you dont use to complex jobs any of these will help you.

  • GUIDE :

    HTTP METHOD - /route - Little description of it behaviour.

      Received or sended object schema.
      Ex: {
      "text":"Lorem ipsum..."
      }
    

    Final thoughts about API behaviour


    Exemple:

    GET - /health - API return status 200 with object below.

    {
      "message":"I'm Alive!"
    }
    

    Simple way to verify if API is up. Maybe is not implemented on this project


    Usage - In this case you will make a GET request on http://localhost:5000/health. And will receive the JSON object "message: I'm Alive!" on the console, terminal or display, depending on the case.


LET'S GO - API description.

POST - /participants - API verify existing users online with same name and, if don't have, includes user on mongoDB.

  {
  "name":""
  }

This route have setTimeout to verify activity, if user frontend dont send new requests in 10 seconds, this user are removed.

GET - /participants - API return one array with online users.

  [{
   "name":"john"
  },{
   "name":"will"
  },...]

POST - /messages - Send message to API redirect for one user or all chat.

HEADER:

{
  "user":""
}

BODY:

{
  "to":"",
  "text":"",
  "type":""
}

Valid types: ["message", "private_message"].

"message": all users can see on chat.

"private_message": only the one user you sended.

PUT - /messages/:message_id - User can edit the message, need id from mongoDB.

{
  "to":"",
  "text":"",
  "type":""
}

DELETE - /messages/:message_id - User can delete the message.

{}

โ›๏ธ Built Using


โœ๏ธ Authors

batepapo-uol-api's People

Contributors

raferdev avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.