Code Monkey home page Code Monkey logo

spring_data_idempotency's Introduction

Spring Data Idempotency

An example implementation of using Redis as a cache along with the H2 database using Spring Data Redis and Spring Data JPA.

We've added the Customer entity which is stored in the H2 in-memory database using Spring Data JPA and POST API endpoint /customer.

  • Example POST curl: curl -X POST "http://localhost:8080/customer" -d '{"firstName":"anshul","lastName":"bansal","email":"[email protected]"}' -H "Accept: application/json" \ -H "Content-Type:application/json"

However, when the Customer record is fetched using the GET API, we require to pass the id of the Customer object and the idempotencyKey in the request header. The application will check if the idempotencyKey exist in the Redis cache and tries to fetch the Customer object from the cache else it will search the H2 database.

  • Example GET curl: curl "http://localhost:8080/customer?id=281407da-5265-468f-b65b-d98d2268b122" -H "idempotencyKey: 0f3123e5-de97-4d4b-b2d5-e59e8ccfd442"

Notes:

  • We've used the UUID for both id and idempotencyKey.
  • Use the id of the Customer object received in the response of the POST API.

spring_data_idempotency's People

Contributors

smartyansh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.