Creating Your REST Controller; Using Postman to Test Requests

4 min readFeb 12, 2022

part two to this.

Now that there is a RestController with the ability to map to functions, time to create the rest of the CRUD capabilities in the controller and test the resources using Postman.

Start by adding the GetMapping annotation to the Read method set the value endpoint using ‘{id}’. This lets the application know this variable will be provided each request. Define the method with a return type of Athlete, passing the id as a parameter. Use the appropriate service method to findAthlete from the repository, return new ResponseEntity with athlete and HttpStatus.

Spring provides a few more annotations necessary for providing metadata about the application structure; ‘@PathVariable and ‘@RequestBody’. PathVariable is used to read variables mapped to the url, or uri. RequestBody is used to map the body to the http request.

The Create method in Crud is used with POST requests that post, or save, objects to our database, mapping them to a table.The body of the request should contain the object that you want to save to the database; passed using the RequestBody annotation. Use the appropriate service method to addAthlete. Return new ResponseEntity, passing the new instance and HttpStatus.Created.

The Update method in Crud is sent with a PUT request. For simplicity, we will update the entire object with a certain id unique to our entity class. The PUT method is not posting a new request but updating one at a unique identity. Use the service method to updateAthlete in the repository. Return new ResponseEntity with updated Athlete and HttpStatus.OK.

The Delete method is sent with a DELETE request. Use the service method to delete an Athlete by id. Return a new ResponseEntity with the appropriate message.

Testing with Postman

This requires a connection to the database that is being used for the application. Start the mysql server, configure database settings in file, connect to the database using the database explorer, making sure the ping is successful and MySQL is connected. No errors should be returned running the main class of the application. For more on connecting the database, here.

Open the browser and navigate to Select Workspaces from the dropdown menu and create a new workspace. This is a space to organize applications and…


Learning. Puttin up shots in Angular and Java and Python and anything else I get my hands on. Sights set on becoming a gainfully employed developer.