Shopping cart microservice

The Shopping cart microservice is closely integrated with the User registration and Product catalog microservices. It holds pending purchases and prepares invoices. It contains the following methods:

  • POST request to /user/uid/cart/, which puts a product in the cart and returns the id of item in the user's cart with the uid
  • GET request to /user/uid/cart/id, which returns information about the item with id
  • PUT request to /user/uid/cart/id, which updates information about the item with id (alters the quantity of items)
  • GET request to /user/uid/cart/, which returns a list of all the items in the cart

As you can see, we don't add an extra "s" to the /cart/ URL and we use the same path for creating items and to get a list, because the first handler reacts to the POST method, the second processes requests with the GET method, and so on. We also use the user's ID in the path. We can implement the nested REST functions in two ways:

  • Use session information to get the user's id. In this case, the paths contain a single object, such as /cart/id . We can keep the user's id in session cookies, but this is not reliable.
  • We can add the id of a user to a path explicitly.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.170.187