- 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.
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
REST API for messages.
Authentication & authorization with JWT
- Spring Security
- Lombok
- Docker
- Jib - Containerize java applications
- Images for x86 architecture, Linux.
- database image already have example data, no need mappings volumes.
- message-service-image will wait for the database service it depends on, this behavior implements with entrypoint.sh & wait-for-service.sh.
- 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
ordocker compose
command. - Simple run
docker compose up -d
- that's all. - See logs via
docker compose logs -f
- See stats via
docker stats
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
frommessage-service-api
module. - Default port 8080, you can change it.
- 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
Write to me in https://t.me/shuricans
Make love, not war!
See ya!