Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:15:37+00:00 2026-06-12T09:15:37+00:00

I have the following route: exports.index = function(req, res){ res.render(‘index’, { title: ‘Express’ });

  • 0

I have the following route:

exports.index = function(req, res){
  res.render('index', { title: 'Express' });
};

I would like to call the following web service: http://ergast.com/api/f1/current/last/results and tell it to return JSON.

I have tried something like this in the index request but it errors:

var options = {
  host: 'ergast.com',
  port: 80,
  path:'/api/f1/current/last/results.json'
};

http.get(options, function(response) {
  response.setEncoding('utf-8');
  console.log("Got response: " + response.statusCode);
  var data = JSON.parse(response);
}).on('error', function(e) {
  console.log("Got error: " + e.message);
}).on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });

I’m guessing I’m probably missing the point somewhere.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:15:38+00:00Added an answer on June 12, 2026 at 9:15 am

    This should be simple 🙂 I recommend you using the request module (npm install request, or just add it to your packages.json file).

    Then you can do the following:

    var request = require("request");
    request.get("http://ergast.com/api/f1/current/last/results.json", function (err, res, body) {
        if (!err) {
            var resultsObj = JSON.parse(body);
            //Just an example of how to access properties:
            console.log(resultsObj.MRData);
        }
    });
    

    I see the suggestion about using JSONP instead of just going straight for the JSON API.

    JSONP’s reason for existing is for cross-domain APIs on the browser. Since you’re running this on the server, the cross-domain restrictions are not an issue and thus JSONP is not required. Go ahead and do as you wish anyway!

    EDIT: I ain’t sure about why you don’t try this. If it is for error management, I have updated the code with error management now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a route like following, ideally I would like it to match: domain.com/layout/1-slug-is-the-name-of-the-page
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have the following route's defined: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute({resource}.axd/{*pathInfo}); routes.MapRoute(
I have the following URl: http://localhost:12981/BaseEvent/EventOverview/12?type=Film This is route: routes.MapRoute( Default, // Route name
I have the following markup: <div id=routes> <ul id=routesList> <li class=routes>Route 1</li> <li class=routes>Route
I have the following route in my Rails3 project: match /blog/:permalink => posts#show, :as
I have the following route: routes.MapRoute( Search, // Route name Search/{affiliateId}, // URL with
I have the following route: routes.MapRoute( edit_product, // Route name Product/Edit/{productId}, // URL with
I'm building a CMS using WebForms on .NET 4.0 and have the following route

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.