Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this package in an API only app (stateless) #249

Closed
Cynically opened this issue Jan 3, 2019 · 2 comments
Closed

How to use this package in an API only app (stateless) #249

Cynically opened this issue Jan 3, 2019 · 2 comments

Comments

@Cynically
Copy link

I'd like to use this package with an API only app and have a separate frontend consume the API to use its cart. How would you approach this? I saw this post but not quite sure what to do with it. Do I save the whole cart serialized in a table attached to a user? What if I want a guest cart?

@lukepolo
Copy link
Owner

lukepolo commented Jan 3, 2019

Its possible, there are two ways (I suggest using the 2nd post 👇 )

First way I don't really suggest doing (as its relies on serializing the object back and forth)

Here are the outlining steps :

  1. seralize the cart and send to front end
  2. on each interaction with the cart you would need to send the entire cart along with it

a POST with data

   {
     cart : __THE_CART_SERALIZED__
     item : __ITEM_YOU_WANT_TO_INTERACT_WITH
   }
  1. When receiving the request , deserialize the cart that was sent,
  2. Use that cart object to do the action
  3. Serialize the cart back up
  4. Return the cart serialized

@lukepolo
Copy link
Owner

lukepolo commented Jan 3, 2019

I prefer this method

Keep track of what they are doing on the frontend ,
and always send all the interactions and generate a new cart based on that .
This would require you to develop your own system of keeping track of items but really it shouldn't be too difficult.

  1. Store items in web storage (that way you can use two windows and know when they update their cart in another window)
  2. Send a request to generate the cart totals , item totals etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants