Giter Club home page Giter Club logo

haruchat's Introduction

HaruChat

A basic REST-API for a chat application using Spring.

NOTE: THIS PROJECT HAS BEEN PUT ON-HOLD.

NOTE: As this project was mainly used for learning purposes, it has private api keys / tokens exposed and does not include any tests (yet).

Core functionalities

  • API that creates basis for a chat platform consisting of multiple users that can start conversations (either direct conversations or group conversations) and exchange messages
  • Full CRUD-Operations supported (see Endpoints)
  • User data securely stored and encrypted in database
  • Integration of Spring-Security:
    • Basic authentication by username (email) and password
    • JWT Token authentication for stateless access without needing to provide the credentials in every request

How it works

(The use of tools such as POSTMAN is highly recommended)

Credentials for basic access

  • username: admin

  • password: password

POST/http://localhost:8080/api/token with basic authentication using the above credentials.

You can now access the API as an admin using the provided JWT-Token as Bearer Token.

To access the database go to http://localhost:8080/h2-console/.
To access the API go to http://localhost:8080/login.

NOTE: (per default this API uses the H2-DataBase which doesn't need additional programs to be used. To change this to MySQL or similar DBMS read here).

Endpoints

Authentication
HTTP URL Authentication Request Body (JSON) Response Body (JSON)
GET /api/welcome no serialized authentication object [empty]
GET /api/token yes (basic) serialized authentication object [empty]

Welcome message:
GET /api/welcome

Request new JWT-Token:
GET /api/token

Users
HTTP URL Authentication Request Body (JSON) Response Body (JSON)
POST /api/users yes serialized user object serialized user object
GET /api/users yes [empty] serialized Iterable
GET /api/users/basic yes [empty] serialized Iterable
GET /api/users/{id} yes [empty] serialized user object
PUT /api/users/{id} yes serialized user object [empty]
DELETE /api/users/{id} yes [empty] [empty]

Save a new user:
POST /api/users

Find all users:
GET /api/users/basic

Find all basic users:
GET /api/users/basic

Find a specific user:
GET /api/users/{id}

Update or replace a user:
PUT /api/users/{id}

Delete a specific user:
DELETE /api/users/{id}

Messages
HTTP URL Authentication Request Body (JSON) Response Body (JSON)
POST /api/messages yes serialized message object serialized message object
GET /api/messages yes [empty] serialized Iterable
GET /api/messages/by/{id} yes [empty] serialized Iterable
GET /api/messages/{id} yes [empty] serialized message object
PUT /api/messages/{id} yes serialized message object [empty]
DELETE /api/messages/{id} yes [empty] [empty]
DELETE /api/messages/{time} yes [empty] [empty]

Save a new message:
POST /api/messages

Find all messages:
GET /api/messages

Find all messages sent by a specific user:
GET /api/messages/by/{id}

Find a specific message:
GET /api/messages/{id}

Update or replace a message:
PUT /api/messages/{id}

Delete a specific message:
DELETE /api/messages/{id}

Delete all messages sent before a certain date:
DELETE /api/messages/{time}

Conversations
HTTP URL Authentication Request Body (JSON) Response Body (JSON)
POST /api/conversations yes serialized conversation object serialized conversation object
GET /api/conversations yes [empty] serialized Iterable
GET /api/conversations/{id} yes [empty] serialized conversation object
GET /api/conversations/of/{id} yes [empty] serialized Iterable
GET /api/conversations/of/{id}/active yes [empty] serialized Iterable
GET /api/conversations/of/{id}/inactive yes [empty] serialized Iterable
PUT /api/conversations/{id} yes serialized conversation object [empty]
DELETE /api/conversations/{id} yes [empty] [empty]

Save a new conversation:
POST /api/conversations

Find all conversations:
GET /api/conversations

Find all conversations of a specific user:
GET /api/conversations/of/{id}

Find all active conversations of a specific user:
GET /api/conversations/of/{id}/active

Find all inactive conversations of a specific user:
GET /api/conversations/by/{id}/inactive

Find a specific conversation:
GET /api/conversations/{id}

Update or replace a conversation:
PUT /api/conversations{id}

Delete a specific conversation:
DELETE /api/conversations/{id}

Setting up persistent database with MySQL

Per default the standard H2-DataBase is used. To change this to a MySQL database:

  1. Create a new schema called "haruchat" in MySQL
  2. Open application.properties
    • change: spring.datasource.url=jdbc:h2:mem:testdb
      to: spring.datasource.url=jdbc:mysql://localhost:3306/haruchat

    • add:

      spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
      spring.jpa.hibernate.ddl-auto=update
      
    • insert your MySQL credentials in spring.datasource.username=and spring.datasource.password=

What's next

  • Adding method level authorization

  • Adding unit tests

  • Integration of this API in a mobile App, most likely written in Kotlin or creation of a React web-app using this API

  • ...

License

Licensed under

GNU Affero General Public License v3.0 ( AGPL-3.0 license )

Carlo Bortolan  ·  GitHub @carlobortolan  ·  e-mail @[email protected]

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.