Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Should I use GET or POST for an endpoint passing or returning anything in Spring Boot?

I have a mail sender method in my Spring Boot app and when I defining related endpoint in the Controller, I could not be sure what is the most proper request for that.

As I do not pass any parameter and the method does not return any content, I am not sure POST or GET is suitable for this. So, which request should I use?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Premised that the choice depends on your personal opinion and habit as developer, and on the specific purpose of your application.

However, in your specific case, I would follow the below logic:

  1. Request is about "retrieving" email -> GET method is better
  2. Request is about "sending" email -> PUT method is better

So the logic is the following: as long as I ask the server to only "retrieve" information and I am not going to send any information to the server (i.e: coming from a form), i will always use GET.
On the other hand, when you also need to pass info to the server and it needs to apply some logic/operation, which might also affect some database, in that case the POST method works better.

Hope that answer your questions. Feel free to add more details, I will strive to help you further.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading