Giter VIP home page Giter VIP logo

shopping_cart_api's Introduction

Shopping_Cart_API

The project was built using Loopback 3

LoopBack is a highly-extensible, open-source Node.js framework that enables you to create dynamic end-to-end REST APIs with little or no coding.

Schema

The model schema of the cart is found below:

Database Schema

The base idea was to create a many to many relationship between carts-and-products using CartItems in-between

Instructions

run the following commands in order

  1. npm install
  2. npm start

if it doesn't run : please try the using the follwing command npm install -g loopback-cli before running npm start again

API Tutorial

Once the application has started navigate to http://localhost:3000/explorer using the browser. You will be greeted with the below page.

Explorer Page

The page has been generated using the Open API specfication UI module.

Two REST APIs have been exposed:

  1. Product
  2. Cart

Products Section

Opening the Product API section will show the list of available exposed methods

Products Exposed Methods

The five basic products given in the requirements specification has already been added. They can be viewed by executing the GET method of the Products. To do so, click on the GET method. This will open a section which allows you to try executing the method and see the output. It provides many functionalities like allowing to add different inputs, and view the response of the methods. Below shows the GET method of the Products open.

Products GET

Executing the method by pressing the try-it-out button returns the result of the method.

Products GET

In the same way products can be added and removed using the POST and DELETE method. Other helper functions have been provided as well.

Eg: GET /Products/{id}/carts checks to see whether a product exists in any carts

Cart Section

In the same vein the Cart section has several helper methods to manage the cart and cart items.

Note: It is possible to create multiple carts.

Cart Section

Once a cart has been created using the POST method (a single cart already exists for testing purposes), products can be added to the cart using AddItemToCart and removed using RemoveItemFromCart.

Adding Items to cart

Clicking on the AddItemToCart shows opens the following sections

Add Item to Cart

By filling the cart_id (which cart to add the product to), product_id (which product to add to the cart), and quantity (quantity of product) and executing the function it is possible to add a product to a cart.

Add Item to Cart Response

Then by calling GET /Carts/{id}/products it is possible to view the products of that cart.

Cart Products

Removing Items from Cart

Conversely by using RemoveItemFromCart it is possible to remove items. It is also possible to remove a certain quantity of a product as well from a cart using this function

Remove Products Response

Disclaimer

It is recommended only use the AddItemToCart and RemoveItemFromCart functions unless you know what you are doing as directly adding cart items will not calculate the total correctly

Database

As the developer was not sure of the availablity of the databases on the testing computer, a persistent in-memory DB provided by Loopback itself was used. The persisted data can be viewed in the mydata.json file.

Note

loopback3 was used instead of loopback4 as Loopback4 does not yet implement a many-to-many relationshipp between models (that I required to connect the cart with the products)

loopbackio/loopback-next#1450

shopping_cart_api's People

Contributors

sajithdil avatar dependabot[bot] avatar

Watchers

 avatar James Cloos 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.