Skip to content

Simple way to make a request sync? #75

Description

@map01ASCIIDOC10

By default browser-request is async but I don't see any obvious way to make it sync. I have two functions, getHTTP and HTTPExists, but I also want to make getHTTPSync and HTTPExistsSync.

What are my options to make them sync?

function HTTPExists(url, cb) {
  request({ url: resolve(url), method: 'HEAD' }, function(err, res) {
    if (err) return cb(null, false);
    cb(null, /4\d\d/.test(res.statusCode) === false);
  });
}
function getHTTP(url, cb) {
  request(resolve(url), function (error, response, body) {
    if (!error && response.statusCode == 200) {
      cb(null, body);
    } else {
      cb(error, body)
    }
  })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions