Tools in Java/Spring to interact with a Restful API [duplicate] - java

This question already has answers here:
Call another rest api from my server in Spring-Boot
(9 answers)
Closed 2 years ago.
I'm building a Java application that needs to access an external Restful API.
I need to perform POST, GET and PUT on this API.
In PHP I used curl and in C# I used HTTPClient.
Which tool should I use in Java/Spring? I'm new in Java and I'm kind lost.

Use RestTemplate as Spring's way of sending HTTP methods
RestTemplate offers templates for common scenarios by HTTP method, in addition to the generalized exchange and execute methods that support of less frequent cases
Here are examples of using GET/ POST/ PUT methods

Related

Which approach is better to handle HTTP (rest PHP+MYSQL structure) with Android (Java)? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have started a new personal project in which I am doing an app for Android with database handling. I am currently doing the login process and I have a few questions before starting to code.
I read that using a RESTful service is the best way to handle databases, at least is was said to be the safest. Java makes the HTTP connection with the PHP file in my server and the PHP file executes the MYSQL sentence. Is this true? Are there more safe options?
At the time of making the HTTP requests, I saw few options: Volley library, Retrofit library, RxJava with Retrofit and using Asynctask with Java and Apache basic libraries (as it can be seen in this tutorial: https://www.tutorialspoint.com/android/android_php_mysql)
I also saw in a Volley tutorial that the data is converted to JSON. Let's say I am not fetching entire rows or column. It is useless then to use JSON? I know that for the sake of future JSON object would be something accesible for everyone, but given is a personal project I could even make a split(",") script to retrieve the data.
For example; if I make a JSON object I would have to write "[key] Result: [pair] fail/ok" if I make a simple retrieve of the String object I would get "Failed" or "Success" directly.
Does it make sense what I am trying to ask?
Firstly you need to make sure you understand what is web service before you create your own web service.
The web service can be achieved by many efficient micro frameworks. For example do some research on Slim PHP, Laravel's lumen, etc. This will process the request sent from Android App, process the data & sends back response to the App. While processing, you will have to fetch data or make changes in the database.
Considering android app, you can choose default http client or third party libraries like Okhttp3, retrofit, volley etc. These are the clients to call the web service & get the response from the server.

Next part is to choose request &response body. This can be JSON, XML etc. JSON is recommended. To handle this JSON response, you default JSON parser to use GSON library.
Have a look at the Weather API by Yahoo, it's a free web service you can call, and is quite well documented. You can find the web service calls & JSON examples here. https://developer.yahoo.com/weather/documentation.html
You have quite a broad set of requirements in your question, please try what I've recommended then come back with refined further questions
Good luck!

Does jersey currently support OAuth 2 on server side?

I want to create REST application with jersey and provide its api for other services. Which approach can be used? I found here answers older than 7 years ago.
Maybe does someone know better aproaches?

Which is the most lightweight way to make an asynchronous http call with Java? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to make an make a web request in an async manner
A very lightweight way in Java to make a synchronous HTTP call is using HttpURLConnection.
Is there an equally easy way to make a non-blocking, 'asynchronous' HTTP call?
I have already looked into: Java NIO, Netty Http Client, Apache Commons HttpClient 4.0 but the solutions are either complex (Java NIO) or introduce a dependency, which I would like to avoid.
HTTP is a synchronous protocol. In this respect I don't think you should see any significant difference from the client side between these 2 cases. But this depends on also what you mean by lightweight

Fetch data from other Website [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I make a raw HTTP request in Java?
I am monitoring a website which updates transaction data every few seconds, so for having better performance I need to store those data and analyze them (like plotting, etc.).
My question is how I can make a request to that server by Java EE and get the values which are available in a table in that site?
I should add that I do not search a solution by .net or php, and I have tried by JQuery, java HTTPRequest but I did not found the solution.
Any idea will be appreciated.
If they provide some sort of API/webservice that is best way to communicate,
if not and if the source site doesn't have any issue with the data you are taking from them you could use HTTP requests to get HTML response and parse the portion you want using JSoup
Have you actually tried anything yourself yet? SO is not a code generation tool.
That being said, this seems to be of interest: How do I make a raw HTTP request in Java?

What is the Java alternative for PHP CUrl [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
How to use curl in Java
cURL equivalent in JAVA
I am a PHP developer, I am very much comfortable with PHP Curl for getting HTML page, as well as posting the form data.
Recently i have a requirement, to do the same functionality in Java, like above. It is very fine if we can do that in Spring FrameWork.
If you want to use something Spring-specific check out the Spring RestTemplate.
The Jersey Client is another REST-oriented API that is popular.
Apache HttpClient is a solid, mature choice.
And of course there are the good old Sun JDK URL and URLConnection APIs.

Categories

Resources