A blog post is available here
- A number of scenarios with third party integrations require the need for a web hook to receive the response.
- Case where a certain action is not completed immediately or is asynchronous, some partners opt to send a final response to a web hook.
- For example, Safaricom Daraja sends the final transaction status and info as a postback/callback to a designated http endpoint;
- Therefore, in development scenarios debugging can be hard as you need to create an internet-reachable http endpoint where you'll receive your postbacks.
- This tool helps you t-shoot this scenario by providing a convenient way for you to quickly receive these postbacks.
- Have your third party send the postbacks to this app via the endpoint
/api/postbacks
and they are streamed real-time to a friendly web UI or Postman Stream where you can inspect and t-shoot.
# Terminal 1
cd frontend
npm i
# npm run dev # run the dev server * DONT Use this option
npm run build
npm run preview # test SSE
# Terminal 2
cd backend
mvn spring-boot:run # resolve dependencies and start the spring-boot server
Access Browser Vite Preview Build at http://localhost:4173/
Postman/Curl - curl --location 'localhost:8080/api/postbacks/stream'
Send a sample postback to test
curl --location 'localhost:8080/api/postbacks' \
--header 'Content-Type: application/json' \
--data '{
"name": "Hello SSE"
}'
- Spring Webflux
- Two API endpoints
POST /api/postbacks
to receive postback andGET /api/postbacks/stream
to stream postbacks. - See PostbackController.java for Implementation.
- Daisy UI
- Vite + React TS
- Browser Support for EventSource
- See Table.tsx for Implementation Logic.
You should not perform the browser test using vite dev server http://localhost:5173/
because of how React StrictMode
behaves in development.
Strict Mode will mount, unmount and mount again the Table Component, and therefore connection to SSE will be broken.
To receive postbacks on your local setup, you can expose the postback endpoint via ngrok
-
Create an account at ngrok
-
On the backend directory shell
cd backend
use your favorite 21 JDKsdk use java 21-librca
-
Ensure docker is running and build a docker image using spring boot cloud native build pack
./mvnw spring-boot:build-image
-
Create an
.env
file at project rootcp .env.example .env
- Confirm you are on project root/directory you cloned into
ls # README.md backend compose.yml demo frontend
- Create an
.env
file
cp .env.example .env
-
Get your NGROK AUTH TOKEN from ngrok Dashboard
-
Add it to
.env
fileNGROK_AUTH_TOKEN='YOUR_NGROK_AUTH_TOKEN'
-
Run Docker Compose
docker compose up
-
Your ngrok endpoint can be seen at the dashboard
-
Back to your postman or Table.tsx replace
localhost:8080
with the ngrok endpoint, you can even use it on partner sandbox as its accesible on the internet.