Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Dan Newton’s 2017 “Simple Spring Boot: Post” tutorial shows a controller accepting a JSON POST request at /persistPerson, returning a status based on validation, and testing the two outcomes with Postman and MockMvc. Its code is a dated example, not confirmation of current Spring Boot conventions.

What the tutorial’s POST endpoint does

The DZone example uses spring-boot-starter-web and spring-boot-starter-test. Its PersonRestController maps POST /persistPerson and takes a PersonDTO from the JSON request body using @RequestBody. The controller passes the person to personService.isValid(person) and branches on the result.

  • If valid: it calls personRepository.persist(person) and responds with HttpStatus.CREATED (201).
  • If invalid: it responds with HttpStatus.I_AM_A_TEAPOT (418).

Newton describes 418 as a deliberately silly choice and discusses possible alternatives. Treat that status as a feature of this particular example, not general HTTP guidance.

Send the example request with Postman

The tutorial’s manual test sends a request to localhost:8080/persistPerson. Start the Spring Boot application first, then configure Postman as follows:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Choose the POST method and enter http://localhost:8080/persistPerson.
  2. Set the content type to application/json; charset=UTF-8.
  3. Choose a raw request body and send JSON with the fields firstName, secondName, dateOfBirth, profession, and salary.
  4. Submit the request and inspect the HTTP status returned by the controller. A valid person follows the 201 branch; an invalid person follows the example’s 418 branch.

The article does not establish the field types or a complete JSON example, so the request values must match the PersonDTO used in the application.

Test the controller with MockMvc

For a repeatable automated check, the tutorial uses @WebMvcTest(PersonRestController.class) with MockMvc. The test serializes a PersonDTO as JSON, mocks the service and repository, and verifies both the HTTP response and the repository interaction.

Valid request

Configure the mocked service to treat the person as valid. The test expects status 201 and verifies that the repository’s persistence method is called once.

Invalid request

Configure the service to reject the person. The test expects status 418 and verifies that the repository’s persistence method is not called.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When to use each testing approach

Approach What it demonstrates in this tutorial
Postman How to set up and manually send a JSON request, then observe the endpoint’s response.
MockMvc How to check response status and whether persistence was invoked in a repeatable controller test with mocked dependencies.

These examples serve different purposes: a manual request makes the HTTP setup tangible, while the controller test checks selected behavior automatically. The tutorial does not claim that they replace every other kind of application test.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Source and version context

This walkthrough summarizes Dan Newton’s DZone tutorial, published April 6, 2017: “Simple Spring Boot: Post”. The source demonstrates its code and testing approach as presented at publication; it does not verify compatibility or best practices for current Spring Boot versions.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.