r/javahelp • u/TheAnt75 • Aug 28 '22
Consuming a REST API using just vanilla Java!
I am a newbie java developer, can build basic CRUD capable spring boot applications. And I am looking for a new job. So one company gave me this HackerRank assignment which involved consuming a REST API but the assignment was restricted to Java only.
Within minutes I realized this seemingly simple task is beyond by scope without Spring. I left the assignment and checked for some solutions, and jeez I kid you not I was horrified beyond my wits. The same thing which can be done in javascript in about 5-6 lines of code was at least 50 lines of code here in java. Check out this link to get an idea of what I am talking about.
As a Java Developer, do people (interviewers) expect you to know this BS by heart? Do you need to know this for your daily tasks (even occasionally)? Do you agree this is a load of crap?
18
u/Abe_Bettik Aug 28 '22
Most of the link you posted is "business logic," that is, code designed for a very specific task.
The actual meat of it, the consumption of the REST Endpoint via URL is 16 lines, which includes string formatting, error handling, and parsing out the response into something readable.
11
u/ImpecableCoward Aug 28 '22 edited Aug 28 '22
Before calling something bs, you should probably try to understand it first.
The only portion that actually has anything to do with calling the api is the getResponsePerPage method, everything else is business logic.
6
u/pronuntiator Aug 28 '22
How is this that much different from using Spring's client or JavaScript? You set the headers and HTTP method, evaluate the status code, and deserialize the response.
Yes, sometimes you may have to dig deeper into how things work. We had some nasty issues with a load balancer and chunking that made it necessary to debug Apache HttpComponents.
6
u/khooke Extreme Brewer Aug 28 '22
I twould be unusual in 'real world' development to consume a REST api without using a library or helper to make it easier, e.g. RestTemplate from Spring. No need to re-invent the wheel when someone's done it for you.
However, everything else in that linked file looks pretty typical. I don't see 50 lines to consume a REST api, I see about 8 in the method at the end. This is not BS. Looks pretty normal to me.
2
u/nutrecht Lead Software Engineer / EU / 20+ YXP Aug 29 '22
As a Java Developer, do people (interviewers) expect you to know this BS by heart?
No. You're expected to be able to google for answers. And frankly looking at your attitude here I would not want to hire you.
•
u/AutoModerator Aug 28 '22
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.