Git Product home page Git Product logo

react-chat-api's Introduction

DogeCodes

Chat API

API for chat application for DogeCodes React course.

This is a simple API server that implements a logic required to correct work of DogeCodes React Chat application.

Requirements

To run this server localy you need to have these requirements:

Installations

Use following commands to run this API-server localy:

git clone https://github.com/dogecodes/react-chat-api.git
cd react-chat-api
npm install
npm run start:dev # or `npm start` for production

Note: Don't forget to start mongod for connection to database.

API

Current version of API is v1, so you need to specify the version of API before every route. For example:

http://localhost:8000/v1/users/me
http://localhost:8000/v1/chats

HTTP

Here's the map of API's HTTP routes:

  • / โ€” routes related to authentication.
    • /signup POST โ€” create new user with username and password.
    • /login POST โ€” log user in with username and password.
    • /logout GET โ€” log out active user.
  • /users โ€” routes related to users.
    • /users GET โ€” retrieve data about all users.
    • /users/me GET โ€” retrieve my user's data.
    • /users/me POST โ€” update my user's information (username, firstName, lastName and city).
    • /users/:id GET โ€” retrieve information about user with specific :id.
  • /chats โ€” routes related to chats.
    • /chats GET โ€” retrieve information about all chats.
    • /chats POST โ€” create new chat with specified title.
    • /chats/my GET โ€” get list of all user's chats.
    • /chats/:id GET โ€” get chat's information with messages by specific chat's :id.
    • /chats/:id POST โ€” send new message to chat with specific :id.
    • /chast/:id DELETE โ€” delete chat with specific :id. Only creator of the chat can delete it.
    • /chats/:id/join GET โ€” join chat with specific :id.
    • /chats/:id/leave GET โ€” leave chat with specific :id.

If you're using Insomnia for debugging APIs, you can download a workspace backup:

Download .zip

Sockets

This API also emmits and listens some socket.io events.

Sockets connection requires authentication with access-token. Here's an example of establishing sockets connection:

import SocketIOClient from 'socket.io-client';

socket = SocketIOClient('path/to/api', {
  query: {
    token: '...your access-token here...',
  },
});

Here's the list of events:

Emmiting

  • new-message โ€” emmited when someone sends new message to specific chat.
  • new-chat โ€” emmited when someone creates new chat.
  • deleted-chat โ€” emmited when someone deletes a chat.

Listening

  • connection โ€” connection of socket.io client.
  • mount-chat โ€” mount a client to listen for messages in chat with specific :chatId.
  • unmount-chat โ€” unmout a client from listening for messages in chat with specific :chatId.
  • send-message โ€” send message with content to chat with

License

MIT ยฉ Denys Dovhan

react-chat-api's People

Contributors

denysdovhan avatar antimech avatar imbuedhush avatar dmitryt avatar

Watchers

James Cloos avatar Anatoliy Bartsev 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.