Skip to content

interledger-deprecated/superagent-ilp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Superagent-ILP

Extension of Superagent to pay for HTTP-ILP

DEPRECATED: This module has been deprecated in favor of ILP Fetch

To use Superagent ILP, combine the superagent module with an plugin (as returned from ilp-plugin in this example).

const superagent = require('superagent')
const plugin = require('ilp-plugin')()
const superagentIlp = require('superagent-ilp')(superagent, plugin)

async function run () {
  await plugin.connect()
  const res = await superagentIlp
    .post('http://localhost:8080/')
    .pay(2000) // pays _up to_ 2000 base units of your ledger, as configured for ilp-plugin

  console.log(res.body)
  // -> { message: 'Hello World!' }
}

run()

Below is an example of an application that can be paid for with superagent-ilp. It's written using koa-ilp.

const Koa = require('koa')
const router = require('koa-router')()
const parser = require('koa-bodyparser')()
const app = new Koa()

const Ilp = require('koa-ilp')
const plugin = require('ilp-plugin')()
const ilp = new Ilp({ plugin })

router.post('/', ilp.paid({ price: 1000 }), async ctx => {
  ctx.body = { message: 'Hello World!' }
})

app
  .use(parser)
  .use(router.routes())
  .use(router.allowedMethods())
  .listen(8080)

About

Superagent extension for ILP HTTP micropayments

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •