FAQ: Responding to Requests with Spring - Using HTTP Method Annotations

This community-built FAQ covers the “Using HTTP Method Annotations” exercise from the lesson “Responding to Requests with Spring”.

Paths and Courses
This exercise can be found in the following Codecademy content:

(Beta) Create REST APIs with Spring and Java

FAQs on the exercise Using HTTP Method Annotations

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Make sure to import the correct Mapping libraries

Why are we using PUT instead of POST if we are creating a new superHero? I thought PUT was for updating, not creating new things.

1 Like

Dear fellow students,
In addition to the PUT/POST mistake I found that the method’s name is getSuperHeros (instead of getSuperHeroes) . Watch it!

2 Likes

I couldn’t get it accepted by the validator before I changed this

@GetMapping

to this

@GetMapping()

I mean c’mon…

1 Like

This one felt unfair. Very misleading.

@RequestMapping(value = "/addNew", method = RequestMethod.PUT)

Given the pattern of what we’re learning, you’d expect the answer to be:

@PutMapping("/addNew")

But nope, they expect @PostMapping, despite PUT being used in the original code. You just don’t expect them to test you to that extent of questioning the existing code in an area that feels"out of scope."

And this is in addition to the typo of “Heros” , which is a more understandable error.

1 Like

I believe it is not intentionally put as misleading, but to encourage you to be more attentive to the details provided. As it shows, please look closely at the method name of the class, which obviously describes the behavior of the method - “createNewHero()”, which is equivalent to POST request of HTTP method, translated to @PostMapping in Spring framework. POST is used to create a new entity, while PUT is defined as to update the specific existing data in the class objects. Additionally, the endpoint argument path also describes the kind of request it should be using. I hope it clears out your confusion. Happy learning!