A fetch client capable of paying for its requests
The code is available on GitHub and the package is published on NPM.
PacketPay is a system for making HTTP requests monetized using BSV micropayments.
The PacketPay client makes a pre-flight request to the server endpoint. If a 402 error is encountered, the client pays the server for the request and the response is returned. If the server does not charge for the response, the response is retured as normal. The Babbage SDK is used for payment.
There is a complementary server middleware for accepting these payments.
npm i @packetpay/js
This example demonstrates a simple request with @packetpay/js
const PacketPay = require('@packetpay/js')
const newsArticle = await PacketPay(
'https://decent-news-site.com/article/2009/Jan/chancellor-on-brink.html'
)
-
url
String The request URL -
fetchConfig
Object? The fetch configuration object (optional, default{}
) -
config
Object? PacketPay configuration object, optional of Babbage SDK is used (optional, default{}
)config.authriteConfig
Object? Constructor parameters for Authriteconfig.ninjaConfig
Object? Constructor parameters for Ninjaconfig.clientPrivateKey
String? Client private key, used with both Authrite and Ninja if providedconfig.description
String? Payment description, if a non-default description is desired
Returns Promise<Object> Containing status
, headers
and body
The license for the code in this repository is the Open BSV License.