This is a sample of how one can expose a REST API to external users and also provide a light weight admin section using ThymeLeaf and boostrap
In order to install and start the application please ensure that you have the following:
- Java JDK (v8+)
- Maven (v3+)
- MySQL (optional MySQL Workbench)
- Spring boot
- Spring security
- JWT
- ThymeLeaf and bootstrap
-
The code can be found in github repo communications
-
Clone repository locally using
git clone https://github.com/garytxo/communications
-
Install dependencies and run test
mvn clean install
-
Start your server using
mvn spring-boot:run
-
To view the REST API endpoints check the swagger documentation http://localhost:8080/swagger-ui.html
-
Also you can login into the admin section using
[email protected]
:admin
By default the application is configured to run against H2 database, in order to change to run against mysql please following the instructions below:
-
create the financial database schema by opening a terminal and executing the following command
`mysql -uroot -Bse'CREATE DATABASE communications'`
-
Update the application-mysql.properties connection details
-
Change the active profile to ``mysql` in the application.properties
spring.profiles.active=mysql
There is a two step policy to use the REST API:
-
One needs to get a authorization token by calling :
curl -X POST "http://localhost:8080/auth/signin" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"password\": \"admin\", \"username\": \"[email protected]\"}"
-
Then using the token in the authoriation header when can perform REST calls such as a new message:
curl -X POST "http://localhost:8080/v1/sms" -H "accept: */*" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBhZG1pbi5jb20iLCJyb2xlcyI6WyJST0xFX1VTRVIiLCJST0xFX0FETUlOIl0sInVzZXJJZCI6MSwiYmFuZHdpZHRoSWQiOjEsImlhdCI6MTU3MDcyMDY5MiwiZXhwIjoxNTcwNzIwODcyfQ.nu4M6ghYD2ohx9KWGhfoD-8CEEzRKXeuNsTPABU5QdY" -H "Content-Type: application/json" -d "{ \"message\": \"Hello world\", \"receiver\": 4175409749, \"sendOn\": \"2019-10-13\", \"sender\": 18445014846}"