Skip to content

SabarishAV/webhook-springboot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Implementing Webhook with Spring Boot

Overview

This project demonstrates how to implement a basic webhook mechanism using Spring Boot. The core concept of a webhook is to allow one application to notify another application about specific events by invoking an API.

For example, in a payment system, we might configure a webhook to call an external API once the payment is successfully processed. Similarly, in this project, when a student is added to a school (in the main application), a corresponding API in the hook application is triggered.

Architecture

The system consists of two independent Spring Boot applications:

  1. Main Application (main) – Handles core operations such as creating schools, registering webhook details, and adding students.
  2. Hook Application (hook) – Represents a specific school's server. It exposes an endpoint that is triggered by the main application via a webhook call.

Workflow

  1. Create a School:
    A new school (e.g., XYZ School) is created via the main application.

  2. Register Webhook Details:
    Webhook configuration is set for a school. This includes:

    • eventName – Type of event (e.g., add, delete, update).
    • endpointUrl – The URL of the endpoint in the hook application that should be called when the event occurs.

    Webhook details are stored in a table and linked to the corresponding school by schoolId.

  3. Setup Hook Application:
    The hook application simulates the server of a specific school. It exposes an endpoint (e.g., /student-added/{name}) that simply logs the student's name when triggered.

  4. Add a Student (Main Application):
    When a student is added to a school, the main application:

    • Accepts schoolId, studentName, and age as parameters.
    • Looks up webhook details based on schoolId and eventName = add.
    • Sends a request to the configured endpoint in the hook application, appending the studentName.
  5. Trigger Webhook (Hook Application):
    The hook application receives the request and prints the student name to the console.

⚠️ Ensure that both applications are running on different ports.

Conclusion

This project demonstrates how to implement a webhook integration between two Spring Boot applications. The flow is as follows:

  1. A school is created in the main application.
  2. Webhook details for the school are configured and linked by schoolId.
  3. The hook application acts as the server for the school and exposes a handler for student-related events.
  4. When a student is added via the main app, a webhook is triggered and the corresponding endpoint in the hook app is called dynamically.

This architecture allows seamless event-based communication between distributed services.

About

Implementing Webhook with Spring Boot

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages