How do I display information from a RESTful API in frontend web app?

How do I display information from a RESTful API in frontend web app?
0.0 0

#1

Hi there. I’m a bit confused about how to display information from a RESTful API in a frontend web application and get this full-stack development going. Am I just going to need to use a lot of jquery to pull JSON from an API or is there a better way I don’t know about?


#2

You can use jquery or pure javascript - my pref is the jquery $.ajax function. If json is returned in the success function you can pull info from the json to display in your ui.


#3

I see so with node.js apps your user requires Javascript. Is there a way to render server-side to avoid the user needing to enable Javascript in their browser? The Javascript requirement won’t affect most users however some disable for privacy reasons and I want to accomdate for them if at all possible.

Second, how do you recommend handling POST input? Can jquery handle that for me?


#4

I am not familiar with node.js (yet) so I can’t comment on that. But you can do a post with jquery, the ajax function has a “method” parameter that you can change to “POST”. Here’s the documentation: http://api.jquery.com/jquery.ajax/


#5

Node.js is server sided, just like PHP. Your users won’t need to have javascript enabled for it to function, so you can render your initial stuff through it. Javascript, on the other hand, will be needed if you’re using ajax to manipulate your content in real time.

What you are talking about is called progressive enhancement and yeah, it is possible to accomplish but also quite laborious if your app\spa\website relies a great deal on javascript\asynchronous calls\real time events.

Generally, you’ll want to have basic navigation and functionality accessible by everybody but keep in mind that the vast majority of websites (even the most well-known) don’t even function (or they do, but in a very limited way) without javascript. As an example, try disabling it on facebook and\or twitter; they will both redirect you to a mobile not-so-pretty-and-dynamic version of the website. Google Maps takes it very lightly instead:

With that said, there are a lot of websites that function correctly without javascript too (Amazon, Google Search, Gmail…) but then again, some of their functionality will be missing (like the autocomplete on Google Search or the Live support chat on Amazon).


#6

So a question - is it possible to use a node.js backend without the user having javascript enabled? As far as I can tell you write the frontend app then an API for the frontend app to get information from the backend. Or should I just use <noscript> tags to tell the user to enable javascript for the site to work properly?


#7

Yes, you can use a node backend even if the user disables javascript. That will continue to function normally as any other server-sided language would. The way you communicate with your backend in other parts of your app (mostly the dynamic ones), though, will have to adapt to the absence of javascript.

I haven’t really used node.js that much to feel comfortable answering your other question, though, sorry!