Sylius / Sylius

Open Source eCommerce Framework on Symfony
https://sylius.com
MIT License
7.83k stars 2.08k forks source link

Rename ApiBundle to RestApiBundle / AdminApiBundle? #7730

Closed pjedrzejewski closed 7 years ago

pjedrzejewski commented 7 years ago

Hi!

This has been following me for a long time and seems like it is last minute to do this. Sylius currently provide RESTful API for the most important entities and operations, like checkout & cart. That being said, they are done as AdminUser, not the Customer. So it is an Admin API.

I plan to introduce a ShopAPI that will provide a different type of API, suitable for SPAs & mobile devices, etc. I am not sure if it will be in core (1.1) or a separate Plugin. That being said, I want to avoid confusion in a situation where we introduce ShopApiBundle and we end up with ApiBundle.

Options:

  1. RestApiBundle
  2. AdminApiBundle
  3. Keep ApiBundle

BC Breaks:

There was no strong BC promise on the API, so I believe we can still do this. Let me know what do you think!

kurakin-oleksandr commented 7 years ago

I vote for AdminApiBundle

Zales0123 commented 7 years ago

If we want to indicate the separateness of Admin* and Shop* APIs concepts, then AdminApiBundle is the best choice 👍

lchrusciel commented 7 years ago

AdminApiBundle + 1

jspizziri commented 7 years ago

@pjedrzejewski,

Sorry if this has been asked and answered elsewhere. But rather than having a separate bundle specifically for a ShopApi, why doesn't the standard API take on that responsibility. The way spree handles this I think is pretty elegant in that, there's a definition of CRUD operations that can occur per Entity by a user with a set of roles within the system.

If the authentication mechanism was abstract so that you could plug and play a method of authentication (e.g. Oauth, WSSE, or JWT via something like the LexikJWTAuthBundle), then the available API operations would resolve to the users permissions within the system. In that case then certain things could be limited like the ability to specify a customer on an order when placed, or the ability to CRUD config etc.

Perhaps this is a dumb idea, and I'm open to that as I don't have a super indepth knowledge of Sylius (yet), but I just thought I'd throw it out there.

Great project!

pjedrzejewski commented 7 years ago

@jspizziri Thanks for your comment! :)

We decided to go with a separate bundle because the API for shop operations is a bit more than just differences in permissions. Example:

Admin REST API is very crudish, and it also includes more data than you usually need in the frontend. Frontend developers (from our experience) are most happy when they get JSON with all information that they just need to put in the right place of the template without worrying about: recalculations, translations, currency formatting, etc. The Admin REST API is more suitable for integrations, where you have access to full data (like all translations at once of the product) and Shop API is for mobile/progressive apps development, where you just want to get a product in specific channel & locale and not worry about anything. Compare these:

https://github.com/Sylius/Sylius/blob/master/tests/Responses/Expected/cart/recalculated_items_total_response.json

https://github.com/Sylius/SyliusShopApiPlugin/blob/master/tests/Responses/Expected/cart/filled_cart_with_product_variant_summary_response.json

jspizziri commented 7 years ago

Thanks for the explanation!