This repository contains a sample project that demonstrates the integration of Keploy with JWT (JSON Web Token) authentication in a Spring Boot application.
Before getting started, make sure you have the following installed:
- Latest version of JDK
- Install Keploy
- Postman for testing APIs
To get started, clone the repository:
git clone https://github.com/jaiakash/samples-java.git
cd spring-boot-jwtThe following API endpoints are available:
-
POST
/users/loginAuthenticate a user and receive a JWT token.
Request Body:
{ "username": "your_username", "password": "your_password" }Response:
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }
-
POST
/users/tokenVerificationVerify the validity of a JWT token.
Request Body:
{ "token": "your_jwt_token_here" }Response:
{ "isValid": true }
-
To run the application, run
keploy run -c "./mvnw spring-boot:run" --delay 240 -
To generate testcases, you can make API calls using Postman or
curl:
-
Login
curl --location --request POST 'http://localhost:8080/users/login' \ --header 'Content-Type: application/json' \ --data-raw '{ "username": "akash@example.com", "password": "password" }'
-
Verify
curl --location --request POST 'http://localhost:8080/users/verify' \ --header 'Content-Type: application/json' \ --data-raw '{ "token": "your_jwt_token_here" }'
To test the application, start Keploy in test mode. In the root directory, run the following command:
keploy test -c "./mvnw spring-boot:run" --delay 240This command will run the tests and generate the report in the Keploy/reports directory in the current working directory.