shuricans / simple-message-api

Simple api with JWT security

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple message api. Security with JWT.

Hi everyone!

Short description

  • Auth endpoint /api/v1/login/ takes a simple json like: {"username":"user","password":"password"}
  • If the credentials are validated, we will get a jwt-token. {"access_token": "jwt-token"}
  • Next we can use this endpoint /api/v1/message/, takes a simple json like: {"username":"user","message":"text"}
  • For all the following requests we attached Authorization header - Bearer_jwt-token
  • If we send, for example - {"username":"user","message":"text"} this message will be saved in database.
  • And we can send, for example - {"username":"user","message":"history 5"} this query fetch the last 5 messages for us.
  • Yep. Pretty simple.

Project has two modules, short overview of the tools.

Database module

common persistence module
contains entities, repositories, specifications

  • Spring Data JPA with Hibernate
  • Postgresql - runtime
  • H2 - test
  • Liquibase maven plugin - version control for DB
  • Integration tests for custom repository methods and specifications
    see test package

Message-service-api module

REST API for messages.
Authentication & authorization with JWT

Other common things:

How run this project?

1. First way - docker compose:
  • Be sure you have docker installed.
  • Grab docker-compose.yml from root directory of this repository.
  • The default mapping port is 8085, you can change it in docker-compose.yml file.
  • Open a terminal in the same directory with docker-compose.yml.
  • Next use docker-compose or docker compose command.
  • Simple run docker compose up -d - that's all.
  • See logs via docker compose logs -f
  • See stats via docker stats
2. Second way - docker & IntelliJ IDEA:

For database recommend using database image
run it with that docker-compose.yml
required version - JDK 11

  • Clone project from github
  • First of all, in parent module run mvn clean install
  • I hope all tests will be passed =)
  • Then run container with database: (use this docker-compose.yml)
  • Then run MessageServiceApiApplication from message-service-api module.
  • Default port 8080, you can change it.

All right, how about test some requests?

  • See requests.txt in root directory of this repository.
  • Be careful, the requests indicate port 8085, you can change it.
  • Be sure you have curl
  • Just follow tips and go!
  • For example, also you can use Postman
Have any questions?
Write to me in https://t.me/shuricans

Make love, not war!
See ya!

About

Simple api with JWT security


Languages

Language:Java 98.8%Language:Shell 1.2%