Skip to main content


Showing posts from January 4, 2018

REST tutorial : Controller layer


This is the last post of our RESTful webservice section 1 ;) . Previous part is here
We still have to implement error handling, security etc

You can find the complete source code here Todoapp

Step 1: Create TodoController annotated with @RestController

Step 2: Implement our methods. Spring will do the REST ;)

Let's test our service using Postman.
start the server, gradle clean bootrun

Test 1: Empty Todos
Note the status: since we do not have any Todos yet, it is 404

Test 2: Create a Todo
We get the 201 status and created Todo's location in header

Test 3: List Todos

Test 4: Update a Todo

Test 5: Delete a Todo

That is all for now, though it is working we are yet to handle errors properly and secure our end points.

REST tutorial : Create repository


This is the 2nd post of our tutorial series. Previous part is here
In this part let's create our domain quickly.

You can find the complete source code here Todoapp
Spring Data JPA Spring Data JPA improves the implementation of data access layers by reducing boilerplate codes. For the repository interfaces Spring provides the implementation automatically.

Lombok Lombok reduces boilerplate code for model objects. It can generate getter, setter, toString, hashCode, equals, constructors for you.

To make it simple, we will have Todo with Id, title and summary.

Step 1: Modify database properties

Step 2: Create Todo model

NOTE: Lombok will eliminate getter, setter, toString, hashCode burden.

Step 3 : Create Todo repository

With magic of Spring that is all ;)