Code Monkey home page Code Monkey logo

money-transfer's Introduction

Money transfer Restful API

I have created the APIs for following operations.

  • Creating and fetching accounts.
  • Credit money into account.
  • Transfer money between accounts.

Requirements

One of the major requirement for this service was that it should be light weight thats why I have chosen the tech stack keeping in mind the memory footprint and througput of librariees used, I have avoided libraries that are known to eat RAM.

Second requirement was regarding the in memory datastore and thread safety.

Tech Stack

  • Spark
  • JOOQ
  • H2
  • Flyway
  • Google Guice

Approach

  • I am using H2 (In memory) database, every time we start the application it gives us a prestine database.
  • Account, Ledger and Transaction tables are being used to provide a consistent and verifiable data store.
  • Long is the unit of money not Double, so 10.75$ is represented as 1075 cents.
  • For simplicity, I am not taking care of currencies. I am assuming that all accounts deal in same currency.

Running Locally

  • mvn -Pjooq-generate
  • mvn clean package
  • java -jar ./target/moneytransfer-jar-with-dependencies.jar

Running tests

  • mvn -Pjooq-generate
  • mvn clean test

APIs

Request Response
curl -X PUT http://localhost:8080/accounts \
-H 'Accept: /' \
-H 'Content-Type: application/json' \
-H 'Host: localhost:8080' \
-d '{"name": "Prashant"}'
{
       "uuid" : "8757ff87-16f4-4a84-bb16-a1db7650e467",
       "name" : "Prashant",
       "balance" : 0
}
curl -X PUT http://localhost:8080/accounts \
-H 'Accept: /' \
-H 'Content-Type: application/json' \
-H 'Host: localhost:8080' \
-d '{"name": "Karan"}'
{
       "uuid" : "da751052-1cd5-441c-8c85-9e638dc9d3df",
       "name" : "Karan",
       "balance" : 0
}
curl -X POST http://localhost:8080/accounts/8757ff87-16f4-4a84-bb16-a1db7650e467/credit \
-H 'Accept: /' \
-H 'Content-Type: application/json' \
-H 'Host: localhost:8080' \
-d '{ "amount": 5000 }'
{
       "uuid" : "8757ff87-16f4-4a84-bb16-a1db7650e467",
       "name" : "Prashant",
       "balance" : 5000
}
curl -X POST http://localhost:8080/accounts/8757ff87-16f4-4a84-bb16-a1db7650e467/transfer \
-H 'Accept: /' \
-H 'Content-Type: application/json' \
-H 'Host: localhost:8080' \
-d '{"to": "da751052-1cd5-441c-8c85-9e638dc9d3df", "amount": 1000}'
{
       "uuid" : "8757ff87-16f4-4a84-bb16-a1db7650e467",
       "name" : "Prashant",
       "balance" : 4000
}
curl -X GET http://localhost:8080/accounts/da751052-1cd5-441c-8c85-9e638dc9d3df \
-H 'Accept: /' \
-H 'Host: localhost:8080'
{
       "uuid" : "da751052-1cd5-441c-8c85-9e638dc9d3df",
       "name" : "Karan",
       "balance" : 1000
}

money-transfer's People

Contributors

prashant-kumar 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.