Skip to main content

Posts

Showing posts from January 4, 2018

REST tutorial : Controller layer

Greetings! 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 service layer

Greetings! Welcome to 3rd part of our tutorial series. Previous part is here Let's quickly build our service. You can find the complete source code here  Todoapp Step 1: Create DTO Step 2: Update model to create from/ to DTO Step 3: Define service interface Step 4: Implement services That is all for our services.

REST tutorial : Create repository

Greetings! 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. https://projects.spring.io/spring-data-jpa/ Lombok Lombok reduces boilerplate code for model objects. It can generate getter, setter, toString, hashCode, equals, constructors for you. https://projectlombok.org 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 ;)