API Bate Papo UOL - A backend application developed using NodeJS and mongoDB

Overview

BatePapoUOL BackEnd

My first backend project! Building an API to the most used brazillian chat app ages ago - Bate Papo UOL!

Table of Contents

Overview

You can make the following requests to the API:

  • POST /participants

Set a username in the data base, you can send a .json body like this:

{
  name: "YOUR_NAME_HERE"
}

  • GET /participants

Get an array of every participant in the data base. There will be an ID, the username and a timestamp Date.now() informing the user last status in the following way:

{
  _id: new ObjectId(NUMBER),
  name: "USERNAME",
  lastStatus: NUMBER
}

  • POST /messages

Insert a message in the collection of messages, specifing to whom the message is being sent*, its type ("private_message", "message", "status") and the text. You can send a .json body like this:

{
  to: "HEADERS.USER",
  type: "TYPE_OF_MESSAGE",
  text: "MESSAGE"
}

*You'll need to inform the receiver of the message as User in the request's headers:

request.post('EXAMPLE_URL/messages', body, {
  headers: {
    User: RECEIVER
  }
});

  • GET /messages

Get an array of objects with all messages in the collection of messages with the sender, the receiver, the type of message ("private_message", "message", "status"), the text and the timestamp of the message (HH:mm:ss) in the following way:

  [
    {
      from: "SENDER",
      to: "RECEIVER",
      type: "TYPE_OF_MESSAGE",
      text: "MESSAGE",
      time: TIME
    }
  ]

  • DELETE /messages/:id

Delete a message sending its ObjectId in the request URL and the username (only the sender of a message is able to delete it) in the request's headers as User, like this:

request.delete(`EXAMPLE_URL/messages/${id}`, {
  headers: {
    User: SENDER
  }
});

  • PUT /messages/:id

Request to change a specific message in the collection of messages informing the messages' ObjectId in the URL. The API will be waiting for the same type of information sent in the POST /messages and the User (only the sender of said message is able to update it) in the headers of the request, like this:

request.put(`EXEMPLE_URL/messages/${id}`,
  {
    to: RECEIVER,
    text: "MESSAGE",
    type: "TYPE_OF_MESSAGE"
  }, {
    headers: {
      User: SENDER
    }
  }
);

  • POST /status

Every 15 seconds, the API will check the lastStatus of every user for a status that wasn't updated in the last 10 seconds and if confirmed, it'll remove the user from the DB. With this route, it's possible to keep updating the user timestamp (lastStatus). Like before, the User needs to be specified through the request's headers.

Data Sanitization

The API will automatically remove HTML tags and unnecessary white spaces from messages and usernames by default. 8)


Built with

The following tools and libs were used in the construction of the project:

How to run

You will need:

  • npm
  • NodeJS
  • MongoDB

Steps:

  1. Clone this repository

  2. Install dependencies

npm i
  1. Start the server
mongod --dbpath ~/.mongo

For more information about MongoDB, access its Documentation.

  1. Start the data base app*
mongo
mongosh

*Obs: open another terminal and use one of the commands above

  1. Get the URL shown on Connected to: mongodb://XXX.X.X.X:XXXXX/ and copy it into the .env file as MONGO_URI=<URL>

  2. Finally, start doing requests to the server

  3. Alternatively, if you want a front-end app to see the API working, you can use:

https://github.com/Lucas-zz/BatePapoUOL_FrontEnd

Author

You might also like...

API em NodeJS, utilizando banco de dados MongoDB (TypeORM), com cobertura de testes (coverages), utilizando o Jest

API em NodeJS, utilizando banco de dados MongoDB (TypeORM), com cobertura de testes (coverages), utilizando o Jest

Api Backend Tindin Sobre API em NodeJS, utilizando banco de dados MongoDB (TypeORM), com cobertura de testes (coverages), utilizando o Jest. 👉 app ur

Jan 20, 2022

@Ifycode's buuk API (nodejs, expressjs, mongodb)

@Ifycode/buuks-express-api Hosted on Heroku: https://buuks-express-api.herokuapp.com "Buuks" instead of "books"... Another angle 😉 The API allows an

Apr 21, 2022

Uma Api dos 151 primeiros pokemons utilizando NodeJS, Typescript, Docker, MongoDB e Mongoose.

Uma Api dos 151 primeiros pokemons utilizando NodeJS, Typescript, Docker, MongoDB e Mongoose.

Pokedex API Tópicos Preview Sobre o Pokedex Api Tecnologias Instalação e uso Preview Clique aqui para ter acesso a um preview da Api. Sobre o Pokedex

Nov 27, 2022

A peroidic-table api built with Nodejs & Mongodb to help make frontend requests dealing with chemistry...

A peroidic-table api for frontend apps Usage Example (GET all elements) // GET /api/elements const ajio = require("ajio") ajio.baseUrl("https://apis-

May 24, 2022

DocuBox is a cloud file storing app built using Kotlin, Nodejs and MongoDb.

DocuBox is a cloud file storing app built using Kotlin, Nodejs and MongoDb.

DocuBox is an app where you can securely upload your files on the cloud – from family pictures and audio recordings to spreadsheets, presentations and other confidential documents. All the files uploaded by the users are stored in an encrypted format.

Nov 18, 2022

Venni backend - The backend of the Venni client apps implementing the credit card payments, matching algorithms, bank transfers, trip rating system, and more.

Cloud Functions Description This repository contains the cloud functions used in the Firebase backend of the Venni apps. Local Development Setup For t

Jan 3, 2022

Gatsby-Formik-contact-form-with-backend-panel - Full working contact form with backend GUI panel.

Gatsby minimal starter 🚀 Quick start Create a Gatsby site. Use the Gatsby CLI to create a new site, specifying the minimal starter. # create a new Ga

Jan 2, 2022

This is an application that entered the market with a mobile application in real life. We wrote the backend side with node.js and the mobile side with flutter.

HAUSE TAXI API Get Started Must be installed on your computer Git Node Firebase Database Config You should read this easy documentation Firebase-Fires

Nov 4, 2021

Nest accessory developed with HAP-NodeJS to allow devices into HomeKit

Nest_accfactory This is a HAP-NodeJS accessory I have developed to allow Nest devices to be used with HomeKit including having support for HomeKit Sec

Oct 9, 2022
Owner
Lucas Azzolini Vieira
Aspiring Web Developer Full-stack. Familiar with #HTML #CSS #JavaScript #React #Git. And with some knowledge in #Java and #C.
Lucas Azzolini Vieira
sistema de bate ponto para os aprendizes da brisa, usando Angular no frontend, golang no backend e postgresql como banco.

Migule Points Este projeto tem o intuito de automatizar a frequência dos aprendizes da brisanet, usando Angular no front, Golang no backend e postgres

Pedro Miguel 3 Sep 26, 2022
This is a full-stack exercise tracker web application built using the MERN (MongoDB, ExpressJS, ReactJS, NodeJS) stack. You can easily track your exercises with this Full-Stack Web Application.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

WMouton 2 Dec 25, 2021
Employee Management System is a web application developed using Django(Backend) which manages the record of employees, their salary, attendance. publish public notices, assign works to employees, make requests to employees.

Employee_Management_System Employee Management System is a web application developed using Django(Backend) which manages the record of employees, thei

Preet Nandasana 7 Dec 16, 2022
The backend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

My first full stack application with the concept of a personal wallet that allows you to create a personal account to keep track of your entire statement by adding incoming and outgoing transactions, as well as calculating the total balance and being able to edit and delete old transactions.

Bernardo Rodrigues 6 Jun 23, 2022
API of my readings, developed in Nest.js, MongoDB, Nginx and Dockerized

My Readings step by step for configuration with docker OBS: required docker and docker-compose cp -r .env.sample .env docker-compose up example what t

William Koller 30 Jul 1, 2022
A developer directory built on Next.js and MongoDB Atlas, deployed on Vercel with the Vercel + MongoDB integration.

MongoDB Starter – Developer Directory A developer directory built on Next.js and MongoDB Atlas, deployed on Vercel with the Vercel + MongoDB integrati

Vercel 246 Dec 20, 2022
Mongo Strict is a TypeScript based smart MongoDB ORM, It makes the usage of MongoDB safer, easier and faster with a better performance...

mongo-strict mongo-strict is compatible with mongo >= 5 Mongo Strict is a TypeScript-based smart MongoDB ORM, It makes the usage of MongoDB safer, eas

Mohamed Kamel 4 Sep 22, 2022
A type speed checking website which lets you check your typing speed and shows the real-tme leaderboards with mongodb as DB and express as backend

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Sreehari jayaraj 8 Mar 27, 2022
⚙️ REST api with NodeJS(KoaJS) MongoDB and Jest Tests.

RESTRIS Functional Backend implementation of REST api with NodeJS(KoaJS) MongoDB and Jest Tests. Tools TypeScript Node KoaJS MongoDB Mongoose Jest Sup

Beatriz Oliveira 8 Dec 2, 2022
Project developed as Capstone of Q4 Backend module of the Fullstack Developer Course of Kenzie Academy Brasil by the group @ezms, @Nafly09, @RafaelSchug, @victorlscherer, @Vinicius2m, @ManoelaCunha

✨ Quokka Services ✨ ?? Serviço rápido e sem preocupação! ?? O objetivo da nossa aplicação é diminuir a dificuldade que moradores de condomínios encont

Manoela Fernanda Girello Cunha 4 May 4, 2022