Code Monkey home page Code Monkey logo

spring-web-and-rest-thymeleaf's Introduction

Spring ThymeLeaf (boostrap) and REST API

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

Prerequisite

In order to install and start the application please ensure that you have the following:

  • Java JDK (v8+)
  • Maven (v3+)
  • MySQL (optional MySQL Workbench)

frameworks used

  • Spring boot
  • Spring security
  • JWT
  • ThymeLeaf and bootstrap

Instructions

  1. The code can be found in github repo communications

  2. Clone repository locally using

    git clone https://github.com/garytxo/communications

  3. Install dependencies and run test

    mvn clean install

  4. Start your server using

    mvn spring-boot:run

  5. To view the REST API endpoints check the swagger documentation http://localhost:8080/swagger-ui.html

  6. Also you can login into the admin section using [email protected] : admin

Change H2 to Mysql database

By default the application is configured to run against H2 database, in order to change to run against mysql please following the instructions below:

  1. create the financial database schema by opening a terminal and executing the following command

    `mysql -uroot -Bse'CREATE DATABASE communications'`
    
  2. Update the application-mysql.properties connection details

  3. Change the active profile to ``mysql` in the application.properties

    spring.profiles.active=mysql

using REST API

There is a two step policy to use the REST API:

  1. 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]\"}"

  2. 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}"

For further info check

spring-web-and-rest-thymeleaf's People

Contributors

garytxo avatar dependabot[bot] 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.