npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

send-webmention

v2.0.0

Published

Send a Webmention

Downloads

22

Readme

node-send-webmention

Build Status Coverage Status Greenkeeper badge

Send a Webmention.

Originally written for similar reasons as get-webmention-url - webmention-client was way overcomplicated and seemed unmaintained.

This project is, however, API-compatible with @connrs' module. The original was extremely sensible in that regard.

Install

npm install send-webmention

Usage

This module is a drop-in replacement for webmention-client with the following exceptions:

  • It uses get-webmention-url under the hood so it supports more discovery mechanisms (and has less bugs)
  • It considers any 2xx response to mean success, not just 202 Accepted
  • It returns the HTTP response object instead of trying to be clever with the body

The module exports a function with several forms:

webmention(source, target[, userAgent], callback)

source (String): the source URL for the Webmention.

target (String): the target URL to send the Webmention to.

userAgent (String; optional): the value of the User-Agent header for all HTTP requests

callback (Function): function that will be called when the Webmention has been sent. See "callback return values" below

webmention(opts, callback)

opts (Object): options object with at least a target key and a source key, plus an optional ua key to set the User-Agent

callback (Function): function that will be called when the Webmention has been sent. See "callback return values" below

Callback return values

The callback function will receive either an error as the first argument or an object as the second argument (never both).

If everything goes (mostly) okay, you'll get the object back. The object will have one or two keys, success (which is a Boolean) and res (which is an instance of http.IncomingMessage and is included only if the target had a Webmention endpoint that we POSTed to). success will be true if the Webmention was successfully delivered and the response used a 2xx status code. Otherwise it will be false.

If an error is encountered during processing (this mostly means HTTP errors), you'll get back an Error instead. Note that a page not having a Webmention endpoint or a non-2xx response will not result in an Error, but they will result in success being set to false.

Examples

var webmention = require('send-webmention'),
    concat = require('concat-stream');

webmention('https://example.com/index.html', 'https://example.org/a_post', function(err, obj) {
    if (err) throw err;

    if (obj.success) {
        obj.res.pipe(function(buf) {
            console.log('Success! Got back response:', buf.toString());
        });
    } else {
        console.log('Failure :(');
    }
});
var webmention = require('send-webmention'),
    concat = require('concat-stream');

webmention('https://example.com/index.html', 'https://example.org/a_post', 'webmention-5000/1.0.0', function(err, obj) {
    // Same thing
});
var webmention = require('send-webmention'),
    concat = require('concat-stream');

webmention({
               source: 'https://example.com/index.html',
               target: 'https://example.org/a_post'
           },
           function(err, obj) {
               // Same thing
           });
var webmention = require('send-webmention'),
    concat = require('concat-stream');

webmention({
               source: 'https://example.com/index.html',
               target: 'https://example.org/a_post',
               ua: 'webmention-5000/1.0.0'
           },
           function(err, obj) {
               // Same thing
           });

Security considerations

This module does absolutely nothing to address the Webmention spec's security considerations section. You need to take care of this yourself.

Version support

Supports Node 6+.

Author

AJ Jordan [email protected]

License

Lesser GPL 3.0+