Coder Social home page Coder Social logo

th3n3rd / sample-product-cart-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unchase/sample-product-cart-api

0.0 1.0 0.0 2.35 MB

Sample shopping cart REST API written with help of Symfony 4 framework

License: MIT License

PHP 88.29% Gherkin 8.32% JavaScript 0.90% HTML 2.49%

sample-product-cart-api's Introduction

Sample product / cart API

This is sample REST service that provides simple functionality of product store and shopping cart.

Requirements

Client should be able to:

  1. add product to the catalog
  2. remove product from the catalog
  3. update product name
  4. update product price
  5. list all products in the catalog as a paginated list with at most 3 products per page
  6. create a cart
  7. add product to the cart
  8. remove product from the cart
  9. list all products in the cart
    • cart can contain a max. of 3 products
    • cart should display a total price of all products in it

Design

Solution is modelled as two "separate" microservices (although for simplicity living in one PHP application). Product microservice provides REST endpoints that allows to manipulate product and persist it in database. Cart microservice provides REST endpoints for manipulating cart and products in cart and persist it in cart database, separate from product database to allow independent scalability of both microservices. For the same reason cart database contains copy of relevant product data (for the sake of availability consistency is exchanged for eventual consistency).

Data synchronization between two services is conducted via event bus. Modifications in product database send appropriate events to event bus to which cart microservice subscribes. In real case scenario event bus would be realized using e.g. RMQ in this case, again, event bus is modelled directly in PHP. Still the only information sent via event bus is unique product identifier, the rest of information must be fetched from product microservice directly. Again, in real world scenario product microservice would expose REST endpoint and cart microservice would use it to fetch information about product. For simplicity this project allows cart service to reuse product repository.

diagram

REST Endpoints Definitions

See raw swagger file or Swagger UI (after you follow "How to run" section).

How to run

# install dependencies
composer install

# make sure tests pass (phpunit + behat), code is clean (phpcs + phpmd) 
composer check 

# start built in www server on port 8000
php bin/console server:run

Now you can play with API directly, or via built in Swagger UI.

Libraries / frameworks used:

Software used in project include:

License

MIT

sample-product-cart-api's People

Contributors

messere 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.