Coder Social home page Coder Social logo

spring-boot-security-data-jpa-h2-rest-swagger-cars-app's Introduction

Cars app with REST Spring Boot, Spring Security, JWT, Spring Data JPA, H2, Maven and Swagger

This is a simple REST API spring boot maven project for CRUD Operations to store/retrieve/remove cars details (brand, model, year of production, car Specifications) and using Swagger to test the Restful endpoints.

Architecture

The application follows the REST architectural style

  1. Controller: is the presentation layer where the end points are located
  2. Service: is the service layer where the business logic resides
  3. Repository: is the persistence layer where the CRUD repository is located

Technologies

The application is created using the following technologies

  1. Spring Boot

    • spring-boot-starter-web
    • spring-boot-starter-actuator
    • spring-boot-starter-data-jpa
    • spring-boot-starter-security
    • spring-boot-starter-validation
    • spring-boot-starter-test
    • spring-boot-devtools
  2. Java 8

  3. Maven Dependency Management

  4. H2 In-Memory database

  5. Json Web Tokens (JWT)

  6. Swagger 2

Unit and Integration Tests

  1. For the Controller: it uses the Spring Boot Test framework with MockMvc, Mockito and hamcrest matchers
  2. For the Service: it uses the Spring Boot Test framework with Mockito and MockBean
  3. For the Repository: it uses the Spring Boot Test framework
  4. For the Integration Test: It uses the Spring Boot Test framework with MockMvc and hamcrest matchers

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You need to install the following software

  • Java JDK 1.8+

  • Maven 3.0+

Installing

Steps to Setup the app

  1. Clone the application

    git clone https://github.com/SayedBaladoh/spring-boot-security-data-jpa-h2-rest-swagger-cars-app.git
  2. Create database schema

    The schema will be generated automatically.

  3. Initialize tables data

    The database tables will be populated with some data by default. If you want to change the default data

    • open src/main/resources/data.sql file

    • change the sql queries

  4. Change database username and password as per you want

    The default database username is sa with empty `` password. If you want to change the database username and `password`

    • open src/main/resources/application.properties file

    • change spring.datasource.username and spring.datasource.password properties as per you want

  5. Change server port as per you want

    The server will start on port 8080 by default. If you want to change the default port

    • open src/main/resources/application.properties file

    • change server.port property and remove comment # before it

  6. Run the tests

    You can run the automated tests by typing the following command -

    mvn clean
    mvn test
  7. Run the app

    You can run the spring boot app by typing the following command -

    mvn spring-boot:run

    The server will start on port 8080 by default, So you'll be able to access the complete application on http://localhost:8080. If you changed the port in src/main/resources/application.properties file, use your custom port http://localhost:port.

  8. Package the app

    You can also package the application in the form of a jar file and then run it like so -

    mvn clean package
    java -jar target/cars-0.0.1-SNAPSHOT.jar
    

Running

To access the app use the following endpoints

  1. Metrics to monitor the app

    • View availble metrics http://localhost:8080/cars/actuator/

    • View app info http://localhost:8080/cars/actuator/info

    • Health check http://localhost:8080/cars/actuator/health

  2. Launch the H2 Console

    To see the database web console

    • http://localhost:8080/cars/h2/ use sa as a username and empty password
  3. Documentation and Examples: Swagger UI

    Use Swagger to view the available Restful endpoints, how to use and test them.

    • http://localhost:8080/cars/swagger-ui.html

    For the services that required authenticated users you must login first to get access token Bearer Token and pass it to the Authorization request header as Bearer token

    You can use username sayedbaladoh and password sayedbaladoh for login or signup first with a new user.

About me

I am Sayed Baladoh - Phd. Senior Software Engineer. I like software development. You can contact me via:

Any improvement or comment about the project is always welcome! As well as others shared their code publicly I want to share mine! Thanks!

License

Licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at

   `http://www.apache.org/licenses/LICENSE-2.0`

Acknowledgments

Thanks for reading. Share it with someone you think it might be helpful

spring-boot-security-data-jpa-h2-rest-swagger-cars-app's People

Contributors

sayedbaladoh1 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.