What's the quickest way to write a simple browser client to talk to a REST server
Asked Answered
S

2

1

I'd like to create a simple browser client that I'll to demo the REST API we have implemented on a server. I need basic functionality like

  1. Create an item on server using POST: client fills up a few parameters and posts
  2. Get list and display using GET: client sends a query, gets an XML list of items and displays them

I don't need any fancy UI, this just for an internal quick demo, a reasonable UI is totally OK.

I know C++, Java, and Perl, but no Javascript. Is JS the easiest way to do this (I am time constrained, have about half a day to implement this)? If so, can you point me to a good resource where I can just pick up the pieces I need?

Sowell answered 19/3, 2010 at 17:25 Comment(1)
I need to display the XML list I get from the server and display it in a somewhat better display than the raw XML display I get with default IE XML display.Sowell
L
2

If you want to write javascript and html/css UI to run in a browser, you could use jQuery and its ajax methods.

$(document).ready(function() {
    $.get("your/restful/url/here", function(data) { // do stuff with data here});
    $.post("your/restful/url/here", function(data) { // do stuff with data here});
});

You could extend the above even further like this:

$(document).ready(function() {
    $("post").click(function() { 
        $.post("/restful/?parm1=" + $("#input1").val() + "&parm2=" + $("#input2").val() , function(data) { // do stuff with data here});
    });
});

<input type="text" id="input1" />
<input type="text" id="input2" />
<input type="submit" id="post">Post</input>

Also, as pointed out in the comments, you could also just simply use your browser to open your RESTful urls.

Librate answered 19/3, 2010 at 17:30 Comment(2)
jQuery and JS did help a lot to cook up a simple client, however, the learning curve was a little more steep than I assumed, esp, concerning the same origin policy limitation. I also used jQuery to parse the XML.Sowell
owch - at least you now know about the single origin policy gotcha - today typically you'd use a npm generator to produce the framework of your client and middleware such as http-middleware-proxy to get around the single origin policy. Take a look at following url for more info :-) #32659639Intercalation
H
0

You can use any of the REST server examples (C#, Java, PHP and node.js) I introduced in my blog. The good thing about these example is that they all expose XML descriptor of the API that could be used later to generate client libraries in many coding languages using Kaltura generator, including type-script, javascript and other front-end coding languages that may meet your needs.

Hophead answered 12/3, 2017 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.