M
M
MarkBogrov2016-10-22 21:18:25
JSON
MarkBogrov, 2016-10-22 21:18:25

How to make simple data output from external json?

Hi friends!
I'm trying to get into the frontend. I wrote a simple backend that, at the url mysite.com/api, gives json with a list of materials like:

[
{
"nid": "1",
"title": "My Title",
"field_image": "<img src="123.jpg">",
"body": "This is body"
},
{
"nid": "2",
...

Well, according to the url mysite.com/api/1 gives JSON op of a separate record.
Question:
What to read to make a simple output for this on pure node / express ?
i.e. I already made a simple application that output data from local jsona like this:
Controller:
var blogJSON = require('../blog.json');

exports.blog = function(req, res) {

  res.render('blog', {
    title: "Блог",
    posts : posts
  });
};

View:
<% for (var i = 0; i < posts.length; i++) { %>
        	<%= posts[i].title %>
    <% } %>

And with an external URL, this trick does not work. Where do you recommend reading? Friendship with Google did not work out, because in general I don’t know what to ask =D
I would be extremely grateful for any kick in the right direction!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2016-10-23
@MarkBogrov

And with an external URL, this trick does not work.

And for this, the request module exists))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question