Skip to content

Simple way to make a request sync? #75

Open

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)
    }
  })
}

Activity

  1. nadavye commented on Dec 30, 2017

    @nadavye

    I think that the current API doesn't support it. Seems like it requires a minor change to the code cause as far as I was able to tell, seems like they create async requests without a way to configure it.

    If you find a way around it, please drop me a line as I need that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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