• Post Reply Bookmark Topic Watch Topic
  • New Topic

Invoking an API from a Java client  RSS feed

 
Jamie Joness
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am looking to invoke the API from here http://glosbe.com/a-api

I'm creating the client in Netbeans IDE 7.4. But when I try to create the client from netbeans, it only gives me the option to do it from wsdl URL and not from an API. How am I able to invoke that glosbe API from my client?

Thanks.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Straight URL access could be done by something as simple as the java.net.URL class: new URL("http://glosbe.com/gapi/....").openStream(), and then slap an InputStreamReader around that, and a BufferedReader around that.
 
Jamie Joness
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Welcome to JavaRanch.

Straight URL access could be done by something as simple as the java.net.URL class: new URL("http://glosbe.com/gapi/....").openStream(), and then slap an InputStreamReader around that, and a BufferedReader around that.


Will this allow me to invoke that API? I'm looking to create a service where users will be able to enter a word into a search box and that will invoke the API available at Glosbe, that in turn will return the definition of the word without the page reloading.

I've been told that I need to create a client so will using the java.net.URL class be appropriate in my situation?

I'm quite new to this so I only know the basics at the moment, any help is very much appreciated.

Thanks.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that would invoke the API, judging by a cursory glance at that link.
 
Jamie Joness
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Yes, that would invoke the API, judging by a cursory glance at that link.


Thank you Ulf, and thank you for the welcome.

I've got that far but nothing happens at the moment. How am I able to make it so that when the user types in a word in the text box and clicks the submit button the definition is displayed on the page below?

Thanks again.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on the context - is this a Swing app? Have you successfully read the output from the stream? Where exactly are you stuck?
 
Jamie Joness
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:That depends on the context - is this a Swing app? Have you successfully read the output from the stream? Where exactly are you stuck?


Not as of yet, I just have the file setup. I'm stuck on getting the output from the API and displaying it back on the web page.

I'm not aware of what a swing app entails.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "displaying it on a web page"? Are we not talking about a Java client, but a JavaScript client? I guess I'm not clear on what exactly you're trying to do right now.
 
Jamie Joness
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What do you mean by "displaying it on a web page"? Are we not talking about a Java client, but a JavaScript client? I guess I'm not clear on what exactly you're trying to do right now.


I'm sorry, I will try to explain it better.

I am required to develop a client browser interface which utilises the dictionary web service at Glosbe.com

The user should be able to enter a word or phrase into an output component and submit it without the page reloading. I want the returned data to be displayed on the same web page without the page reloading. The returned data needs to be displayed so that the user can read it easily and see the meaning to the word.

I'm looking to do this within a JS function and a HTML web page. I'm open to using either JSON or XML for the output.

Thanks again.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSON is much easier to deal with in a JavaScript context. jQuery can do this: https://api.jquery.com/jQuery.get/ . The very last example on that page shows how to put the returned data onto the web page. You'll want something more elaborate, but it's a start.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!