8

Academic task… First we were told to generate a set of static .html files showing election results in various administrative divisions. Then we were told to "modernize" this by using Django templates. Fair enough, I can see the benefits of such approach.

But then we were told to further "mordernize" this by making the app "RESTful". As far as I can tell this means that the server may only expose an API that responds to requests by sending clients raw data in the JSON format; the client, which is a static HTML+CSS+JS site, must receive this JSON and then dynamically construct the webpage on the browser side with JavaScript.

Since I’ve sadly missed a few lectures, when this must’ve been explained, could anyone explain to me what are the benefits of such an approach? Because I must say I can only see drawbacks:

  • Users with disabled JavaScript will be unable to view the page.
  • Correct me if I’m wrong, but AFAIK the contents of such a site will hardly be able to be indexed by Google.
  • It will be impossible for users to bookmark the election results in a particular division. Instead, each time they visit the side, they’ll have to click their way through to make JavaScript load the results from that particular division. Or deploy a Selenium bot that does this for them.
  • It breaks back/forward browser buttons.
13

Technically, a web server that serves HTML pages is RESTful. Text/Html is a valid perfectly valid representation, as long as the media type is properly set, according to the uniform interface. Just don't abuse your verbs (GET, POST, etc) and follow HATEOAS (i.e. essentially use a sensible URL that uniquely identifies a resource) and bam it's restful.

I think what your professor is asking is that the your web pages use a RESTful API which often returns json (but again can return any media type that the client will accept).

As for your objections:

Users with disabled JavaScript will be unable to view the page.

Well, they won't be able to get any dynamic content. The page can still contain static content.

Correct me if I’m wrong, but AFAIK the contents of such a site will hardly be able to be indexed by Google.

The static content, including the meta tags, can still be crawled without issue.

It will be impossible for users to bookmark the election results in a particular division. Instead, each time they visit the side, they’ll have to click their way through to make JavaScript load the results from that particular division. Or deploy a Selenium bot that does this for them. It breaks back/forward browser buttons.

Nah. If you a properly following HATEOAS, the URL should provide all the state information required to render the page, and it if it's in the URL, it's bookmarkable.

| improve this answer | |
  • Thank you, but there’s one thing I don’t understand. If the URL contains all the information, then I’m sending a request to the server to get all election results for this administrative division, and if I follow the task specification, I’ll get a JSON… No, as per the requirements, I am to crawl this JSON through XMLHttpResponse, which does not affect what is shown in the browser address bar.! So, for whichever administrative division I view election results, the bookmarkable URL is the same and points to the main page. – gaazkam May 17 '17 at 0:13
  • 4
    True. if your javascript makes dynamic changes to the page, normally the URL won't update to match. But you can make it match if bookmarking is important. See pushState and replaceState and possibly location.hash for the means of doing this. – John Wu May 17 '17 at 0:27
  • 1
    And actually, if you're using push state correctly, Google will crawl the dynamic content as well: newmediacampaigns.com/blog/… – Paul May 17 '17 at 2:01
  • 2
    +1 (particularly for mentioning that html responses can be RESTful), but haven't Google's spiders been executing JavaScript for some time now? – RubberDuck May 17 '17 at 2:49
  • Decoupling frontend and backend with a standard communication API system. – sgargel May 17 '17 at 6:28
0

It's a subtle distinction, but you're moving from a web page to a web application. In a web page, the server and client are tightly coupled; your only option for viewing information is via the web page.

By moving the data into a RESTful web service, the view (what used to be the web page) and the model (the data) are completely decoupled, and your options for interacting with the data are increased.

| improve this answer | |
0

A REST API, like any API, makes the resources available in a machine readable interface any client can use.

If you use that API to build your website you are one of possible many applications using the same service.

Advantages of the REST style are: - use an existing protocol (here HTTP) to exchange the data - you use defined media types to exchange resources.

This means other developers can use existing knowledge and tools to use your API.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.