Code Monkey home page Code Monkey logo

bookstore-spring's Introduction

Getting Started

The Bookstore application was developed using the following technologies:

Prerequisites

Before running or testing the application we need to configure our database.

  • Please run commands from the terminal in create-db.txt to create application database and user.
  • Please run commands from the terminal in create-test-db.txt to create test database and user.

Note: I use MySQL default port when connecting to the database. You can change connection settings for the application in src/main/resources/application.properties and for running tests in src/test/resources/application-test.properties.

Running the application

I use Gradle for building, testing and running the application.

  • To build the app open the terminal and run the following from the project folder:
        ./gradlew clean build -x test
  • To run tests run the following from the project folder:
        ./gradlew test
  • To start the Spring Boot server run the following from the project folder:
        ./gradlew bootRun

Testing REST API endpoints

Once server starts you should be able to access Swagger UI in your browser from http://localhost:8080/api/swagger-ui/ From there you have options to test all the available API methods.

Note: by default the application starts without OAuth2/JWT security enabled. Unfortunately, Swagger UI doesn't support Auth0 and Okta authentication currently.

Testing REST API endpoints with OAuth2/JWT security enabled

To enable OAuth2 security:

  1. Open src/main/resources/application.properties
  2. Uncomment the following line:
  #spring.profiles.active=oauth2
  1. Restart the Spring boot server (Ctrl+C then ./gradlew bootRun)

Once server starts the REST API endpoints will be secured according to the rules defined in java/com/instrument/bookstore/config/OAuth2WebSecurityConfig.java

Like I mentioned above we can't use Swagger UI to test the secured endpoints. Instead, I provided Postman (https://www.postman.com/downloads/) collection export postman/Instrument Bookstore.postman_collection.json with all requests pre-configured.

You may need to re-generate Bearer access tokens while testing requests with Postman if they are expired. To do so please run ./generate-token.sh script and then copy the access token hash from the generated output and paste it into the Authorization tab of a request in Postman.

Note: I use Auth0 authorization server to generate JWT tokens according to the Client Credentials flow (https://auth0.com/docs/flows/client-credentials-flow) for simplicity.

bookstore-spring's People

Contributors

maxopencode avatar

Watchers

 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.