Learn

Responding to HTTP requests is a complicated process. Thankfully, the Spring framework handles this complexity and allows us to easily use the functionality. Even when exceptions are thrown in Spring applications, the framework provides a way for us to access more information about the errors using the ResponseStatusException class or the @ResponseStatus annotation.

With the annotations we learned in this lesson, we can now:

  • Map HTTP requests to controllers and methods (@RestController and @RequestMapping)
  • Specify a path attribute to become a base path (@RequestMapping at the class level)
  • Declare request types using HTTP method annotations (@GetMapping, @PostMapping, @PutMapping, and @DeleteMapping)
  • Access request parameters in a method (@RequestParam)
  • Bind data using template variables (@PathVariable)
  • Fine-tune the status code returned by a method (@ResponseStatus)

All of these annotations and ResponseStatusException are imported from the org.springframework.web.bind.annotation package.

Great work and happy coding!

Instructions

Look through SuperHeroController.java for some of the annotations we covered so far. Make sure you can describe what each one does before moving on.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?