The simplest way to start sending webhooks in PHP.
0.0.29 downloads4 stars
PHP
[!WARNING]
This package is abandoned and the repository is archived. It will get no further fixes,
including security fixes.
For Laravel applications, use juststeveking/api-toolbox,
which signs and verifies webhooks with HTTP Message Signatures
(RFC 9421), the IETF standard. Outside Laravel, use
any RFC 9421 implementation.
Terminal window
composerrequirejuststeveking/api-toolbox
The simplest way to start sending webhooks in PHP.
Installation
You can install this library using composer:
Terminal window
composerrequirejuststeveking/webhooks
The next step is to install a OSR compliant package to do the request itself, you will need:
PSR 7 Request Library
PSR17 Request and Stream Factories
PSR18 Http Client
This package will auto-discover these packages you have installed for you, so you not need to wire anything up.
Usage
This package is super simple to get started with, all you need to do is build one class and you can start sending webhooks.
use JustSteveKing\Webhooks\Webhook;
classYourWebhookextendsWebhook
{
publicfunctionheaders():array
{
$signature =hash_hmac(
algo:'sha256',
data:\Safe\json_encode(
value:$this->buildPayload(),
flags:JSON_THROW_ON_ERROR,
),
key:'Your signing key goes here',
);
return[
'Content-Type'=>'application/json',
'Signature'=>$signature,
];
}
publicfunctionbuildPayload():array
{
return[
'foo'=>'bar',
];
}
publicfunctionurl():string
{
return'Your URL goes here.';
}
publicfunctionmethod():Method
{
returnMethod::POST;
}
publicfunctionplugins():array
{
return[];
}
}
The HTTP Client used for sending your HTTP requests supports plugins, you can see how these work here.
Tests
There is a composer script available to run the tests:
Terminal window
composertest
However, if you are unable to run this please use the following command:
Terminal window
./vendor/bin/pest
Security
If you discover any security related issues, please email juststevemcd@gmail.com instead of using the issue tracker.