/nodejs.urx

URl eXaminer

Primary LanguageJavaScript

urx

URl eXaminer

Description

Verify the availability of URLs in supplied document. urx will try to request the URLs one by one. By default, those responsed successfully with statusCode >= 200 and < 400 will be marked with check sign √ (U+221A) and followed with the statusCode, the others will be marked cross sign × (U+00D7) and followed with statusCode or error message if no response available. You may also customise requesting gestures and define expected responses, see API or Supported Text Formatting.

ToC

Get Started

# Install globally.
npm install -g urx

# Examine URLs in foobar.md.
urx foobar.md

API

urx also offers API to verify URL in code:

const urx = require('urx');

urx(options, (err, ret) => {
    if (err) {
        // ...
    }
    else {
        // ...
    }
});

urx(options)
    .then(function(response) {
        // ...
    })
    .catch(function(ex) {
        // ..
    })
    ;
  • Promise urx(string urlname)
  • Promise urx(object options)
  • void urx(string urlname, Function callback)
  • void urx(object options, Function callback)

In argument options:

  • options.url string
  • options.request object OPTIONAL
  • options.request.headers object OPTIONAL//
  • options.response object OPTIONAL
  • options.response.statusCode number OPTIONAL
  • options.response.headers object OPTIONAL

options.request is used to customise the request. And options.response descibes the expected response.

In promise mode:

  • On-resolved argument will be an object containing only one property response.
  • On-rejected argument will be an error.

In callback mode:

  • Function callback will receive one or two arguments.
  • The first represents an error and will be equal to null if the URL is available.
  • The second will be absent or be an object containing only one property response.
  • Here is something unusual that the second argument MAY be present even when the first one is not null that means the URL is not available.

Refer to htp to find what response is.

Supported Text Formatting

So far, Markdown is the only text format accepted by urx:

  • The URLs expected to be examined should occupy an entire line.
  • Lines start with ^. are indicators for urx.
<!-- The following URL will be examined. -->
http://www.example.com/

<!-- Use simple JavaScript code in URL. -->
http://www.example.com/?time=${Date.now()}

<!-- The next command line tells urx to skip following URLs. -->
^.IGNORE.START
http://1.example.com/
http://2.example.com/
^.IGNORE.END
<!-- Stop skipping. -->

^.RESPONSE.statusCode 302
<!-- The next URL is expected to be responsed with statusCode 302. -->
<!-- This command will be applied on ONLY the first following URL. -->
http://302.example.com/

^.REQUEST.headers { "Host": "www.example.com" }
<!-- The next URL will be sent together with special headers. -->
<!-- This command will be applied on ONLY the first following URL. -->
http://10.0.0.1/

Here is an example of test case written in MarkDown (please read in Raw mode).