January 21, 2017 Uncategorized

Spring Boot REST API protected with JWT

Protecting a REST APIs with JWT is a tedious task and, normally, it is quite similar in common projects. To avoid this tedious task I have developed a Yeoman generator generator-spring-rest-jwt that automatically generates the skeleton of an Spring Boot API REST that is protected with JWT.

The first step is to install Yeoman and install the generator:

After that, you have to generate your project with this command:

Once you have created your project you can get an access token for the following accounts:

There are three endpoints that creates this generator:

If you want to get a token for admin, you have to send a POST request to the endpoint /auth with the following JSON in the body request:

Then you will get a token and you can use it passing it in your requests header:

Creating new endpoints

If you want to create new endpoints then you can run the following command inside the project folder:

This will generate a basic Entity, a JPA Repository and a REST Controller with CRUD operations.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Back to top https://inspirelivinghq.com/