Greetings!
In this tutorial series, we are going to study RESTful services with Spring.
We are going to build a TodoApp in this series since it is one of the easiest way to touch the technical stack.
You can find the complete source code here Todoapp
For the simplicity i'm going split tutorial into smaller parts.
Congratulations!!! you just created your first service ;)
In this tutorial series, we are going to study RESTful services with Spring.
We are going to build a TodoApp in this series since it is one of the easiest way to touch the technical stack.
You can find the complete source code here Todoapp
For the simplicity i'm going split tutorial into smaller parts.
- Section 1: CRUD
- Section 2: Error handling
- Section 3: Security
- Section 4: User interface
- Section 5 : Miscellaneous
Goal
- Create a RESTful service using Java tech stack.
What you need
- Java 8
- Gradle 4
- IDE
REST
REST stands for REpresentational State Transfer. It is an architectural style rather than a strict protocol. Not a standard but a set of constraints, such as being stateless, having a client/server relationship, and a uniform interface.
Spring Framework
The Spring Framework is an application framework and inversion of control container for the Java platform.
Spring Boot
Spring boot is a Spring based production-ready project initializer which create Spring-powered, production-grade applications and services with absolute minimum fuss.
HTTP methods
HTTP Verb | CRUD |
---|---|
GET | Read |
POST | Create |
PUT | Update |
DELETE | Delete |
HTTP Status Codes
HTTP code | Status |
---|---|
200 | OK |
201 | Created |
204 | Deleted (No content) |
400 | Bad Request |
401 | Unauthorized |
403 | Forbidden |
404 | Not found |
405 | Method not allowed |
Define our REST API
First of all let's define our API.- return all Todo entries: '/todos' : GET request
- create a new Todo entry : '/todos' : POST request
- delete a Todo : '/todos/{id}' : DELETE request
- update a Todo : '/todos/{id} : PUT request
- view a Todo: '/todos/{id}' : GET request
Create the starter project
- Go to http://start.spring.io/
- Enter Group and Artifact
- Select Web, H2, JPA and Lombok dependencies
- Click Generate Project to generate and download the project
- Create HelloController and add following,
- Go to project location and run the project
- Go to web browser and enter http://localhost:8080/
Really helpful
ReplyDelete