I have a Rails API and my endpoint to load some user info is:
# at user controller
def load_user_info
user = User.find_by(id: params[:id])
if user.blank?
# Here I call an external service to crawl user info from
# some webpage, and after get this info I save it in my database
else
user
end
end
In this situation, should my route for load_user_info should be a GET or a POST ?
I already took a look in these two questions, but is not clear enough for me because I only save some data if the user doesn't exist, and if my user doesn't exist is not this method of my controller that will save something in my database, it'll be my external crawler class, this crawler class will get the info from website and than do User.create(attributes)
, so to my front end page (that will use this API) this endpoint is just responsible to return user info, my client doesn't know about any insert in my database
When do you use POST and when do you use GET?
When should I use GET or POST method? What's the difference between them?