Spring boot API for a Person CRUD
These are the basics steps to build a model CRUD API with Spring Boot.
Java 11 (Optional) IntelijIDEA Docker
- Go to start.spring.io and create a Spring Boot 2 application with Maven, Java 11 and Spring Web Dependencies.
- Open with Intellij by selecting the pom.xml file inside the project.
- Now you can do the initial commit.
- Create the packages needed for the structure: api, dao, model and service.
- Create initial classes:
- Model (person)
- Dao Interface to be able to change Database implementation later on.
- In-Memory Database implementation of the Dao interface.
- The Service class to interact with the Database.
- The controller that handles user request to the API.
- Add Spring Boot annotations :
- @Repository("name_of_the_repo_impl")
- @Service
- @Autowired
- @Qualifier("name_of_the_repo_impl")
- @RestController
- @RequestMapping("api/version/model")
- @PostMapping, @GetMapping(path = "{field}"), @DeleteMapping(path = "{field}"), @PutMapping(path = "{field}")
- @PathVariable("field")
- @RequestBody Model model
- @JsonProperty("field")
- Implement the CRUD methods on the Dao In-Memory class and test on Postman client on localhost:8080/api/version/model
- Add validation annotations on model fields, and controller
- @Valid, @NonNull, @notBlank...
- Create a Docker container for the Postgres Database
- Spring Boot - Framework used
- Maven - Dependency Management
This project is licensed under the MIT License - see the LICENSE.md file for details