Python Forum
Can we automate Java based Webservices - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Can we automate Java based Webservices (/thread-25225.html)



Can we automate Java based Webservices - PythonBeginner_2020 - Mar-24-2020

Hi All,
I do not have idea on web-services API which is exposed .
here my question may be confusing , or I may not be able to explain.

Basically we have J2EE application that is one Monitoring tools, written in JAVA, that has REST API available, can we access those API using python and can we do the automation, or for doing automation activity we have to learn Java to access those REST API which is in Java. is there way I can find the difference?

Regards.
PythonBeginner


RE: Can we automate Java based Webservices - ndc85430 - Mar-24-2020

Of course you can access the REST APIs in Python - those APIs are meant to be accessed by machines. You can use Requests to make the HTTP requests.


RE: Can we automate Java based Webservices - snippsat - Mar-24-2020

As mention bye @ndc85430 this is common task to do with Python.
Requests make it easy to do GET and POST request.
A example YouTube API,usually with big API you get a API key(free here) to use.
Example find how many subscriber a channel has,so insert key and channel id with f-string.
As a standard usually get JSON back,it's a dictionary when use it from Python.
import requests
 
api_key = 'xxxxxxxxxxxxxx'
channel_id = 'UC5kS0l76kC0xOzMPtOmSFGw' # chess.com
response = requests.get(f'https://www.googleapis.com/youtube/v3/channels?part=statistics&id={channel_id}&key={api_key}')
json_data = response.json()
print(json_data['items'][0]['statistics']['subscriberCount'])
Output:
285000



RE: Can we automate Java based Webservices - ndc85430 - Mar-24-2020

(Mar-24-2020, 09:28 AM)snippsat Wrote: As a standard usually get JSON back,it's a dictionary when use it from Python.

Not necessarily though; some APIs serve XML. Thankfully Python includes an XML parsing library in ElementTree.


RE: Can we automate Java based Webservices - snippsat - Mar-24-2020

Yes can also get XML,CSV or sometime a choice what format to get back,that why say i did say "usually".
(Mar-24-2020, 09:32 AM)ndc85430 Wrote: Thankfully Python includes an XML parsing library in ElementTree.
Yes,but i never use parser in standard library,use BeautifulSoup 4 or lxml.


RE: Can we automate Java based Webservices - PythonBeginner_2020 - Mar-25-2020

Thanks alot for you the input here