JSON Api parsing in Elixir

Is it possible to parse outside API in Elixir in a similar way below? Or do I use Path Helper; user_path(Endpoint, :show, 17, admin: true, active: false) ?

router.get('/', function(req, res, next) {
  const url = "https://newsapi.org/v2/top-headlines?pageSize=20&category=business&apiKey=920204";
  request.get(url, (err, response, body) => {
    if(err) { console.error(err) }
    body = JSON.parse(body);
    const imgUrl = body.articles[1].urlToImage
    res.render('index', { title: 'The News', imgUrl: imgUrl});
  });
});

I think this might work. https://stackoverflow.com/questions/46633620/make-http-request-with-elixir-and-phoenix

To make the HTTP request, you could use an HTTP client. I most often use HTTPoison.

To parse the JSON data returned you can use any of a number of JSON parsing libraries. A popular ones include Jason and poison

2 Likes