0

Nowadays i am learning REST but i couldn't understand its way of usage. Probably this is perfectly easy question but since i have lack of knowledge about concepts i am totally confused.

Let say i have a simple Spring MVC application and i run localhost:8080/greeting/?id=1 and it shows my greeting.html page and some data from my database. So far so good.

But when i change my @Controller to @RestController and call localhost:8080/greeting/1 i get a json as following {"id":1,"content":"Hello, World!"}. I understand this is normal because this is a response of rest service.

But how to use it in my greeting.html? i mean what is the concept to map this data to my html page?

Thanks in advance

Altan

Community
  • 1
  • 1
Altan Gokcek
  • 71
  • 2
  • 8
  • 1
    Typically you would use some client code to get this JSON data. A client could be a JS client executing a HTTP GET request in your greeting.html – reto Jul 07 '16 at 08:30
  • Possible duplicate of [What exactly is RESTful programming?](http://stackoverflow.com/questions/671118/what-exactly-is-restful-programming) – diyoda_ Jul 07 '16 at 08:33

2 Answers2

1

There are multiple tutorial that explain how to consume RESTful Web Service on Spring.io website :

You just have to choose the method with which you are most familiar.

Mickael
  • 4,003
  • 2
  • 25
  • 37
0

you can use jQuery to parse this json String

var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );

then your can set value like this

<p>Input field: <input type="text" id="test" value="Mickey Mouse"></p>

$("#test").text(obj.name);
shiqin zhang
  • 313
  • 1
  • 3
  • 16