Skip to content

Simple service to receive callbacks. Useful for when testing APIs locally that send callbacks

Notifications You must be signed in to change notification settings

leeturner/callback-logger

Repository files navigation

callback-logger

buildStatus latestVersion Twitter: leeturner

Simple service to receive callbacks. Useful for when testing APIs locally that send callbacks

🦿 Prerequisites

  • Java 17 or above

🛠 Installation

  1. Download latest sources and run:
./gradlew build run

⌨️ Usage

Once up and running you can set the callback url of the API you are testing to the callback endpoint of callback-logger - http://localhost:7070/callback-logger/api/callback. Both POST and PUT methods are supported for the callback endpoint along with multiple content types. You can send a callback manually using the following curl request:

curl -X POST --location "http://localhost:7070/callback-logger/api/callback" \
    -H "Content-Type: application/json" \
    -d "{\"hello\": \"world\"}"

or

curl -X PUT --location "http://localhost:7070/callback-logger/api/callback" \
    -H "Content-Type: application/xml" \
    -d "<hello>world</hello>" 

Custom callbacks

If you need to send callbacks to different callback endpoints than the default callback-logger endpoint then you can define custom callbacks. Custom callbacks are defined in the application.conf file and are defined as a list of put or post URIs. For example:

callback-logger {
  custom-callbacks {
    post = ["/api/custom1", "/api/custom2"]
    put = ["/api/custom1"]
  }
}

Any duplicate URIs will be ignored and all custom URIs need to start with a /. You can then send callbacks to the custom endpoints using the following curl request:

curl -X PUT --location "http://localhost:7070/api/custom1" \
    -H "Content-Type: application/xml" \
    -d "<hello>world</hello>" 

Specify the http response code

By default, callback-logger returns a 200 response code for all callbacks. If you need to return a different response code then you can define the response code in the application.conf file. For example:

callback-logger {
  custom-callback-response-code = 201
  callback-response-payload = ""
  custom-callbacks {
    post = ["/api/custom1", "/api/custom2"]
    put = ["/api/custom1"]
  }
}

The application will fail to start if the response code is not a valid http response code.

Specify the http response payload

By default, callback-logger returns an empty string as the response payload for all callbacks. If you need to return a different response payload then you can change that in the application.conf file. For example:

callback-logger {
  custom-callback-response-code = 200
  callback-response-payload = "{\"status\": \"OK\", \"message\": \"Callback received\"}"
  custom-callbacks {
    post = ["/api/custom1", "/api/custom2"]
    put = ["/api/custom1"]
  }
}

Web UI

callback-logger provides a simple web interface to allow you to see the callbacks you have received. You can access the web interface by pointing your browser to http://localhost:7070/callback-logger:

🥼 Run tests

./gradlew test

✍️ Author

👤 Lee Turner

Feel free to ping me 😉

🤝 Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Open an issue first to discuss what you would like to change.
  2. Fork the Project
  3. Create your feature branch (git checkout -b feature/amazing-feature)
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a pull request

Please make sure to update tests as appropriate.

❤ Show your support

Give a ⭐️ if this project helped you!

Buy Me A Coffee

☑️ TODO

  • Setup releases using jReleaser

📝 License

Copyright © 2023 - Lee Turner

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

This README was generated by readgen

About

Simple service to receive callbacks. Useful for when testing APIs locally that send callbacks

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published