Filippo Grecchi
Filippo Grecchi

Reputation: 51

Integrating customised APIs in Spartacus Storefront

our Hybris instance has some custom REST APIs, for example the addEntry. This version of the API requires an extra boolean parameter in the payload, let's call it fooBar. Here’s an example of payload:

{"quantity": 1, "product": {"code": "1234567"}, "fooBar": false}

Here’s the list of what we’ve done in order to have this extra parameter in the service that actually made the http call:

[
    { provide: ActiveCartService, useClass: E2ActiveCartService },
    { provide: MultiCartService, useClass: E2MultiCartService },
    E2CartEntryEffects,
    { provide: CartEntryConnector, useClass: E2CartEntryConnector },
    { provide: E2CartEntryAdapter, useClass: E2OccCartEntryAdapter },
]

This solution seems to work but we think that's pretty complex for a relatively simple change and we would like to know if our approach is correct or if there is a better, cleaner way.

Kind regards

Upvotes: 5

Views: 499

Answers (1)

dunqan
dunqan

Reputation: 974

Currently, it seems like the correct way for this specific use case.

You did not exactly specify what fooBar is used for, but I assume, it's used and can be toggled inside the top-level layer (in UI component) and has to be passed by all other layers down to the adapter.

On the other hand, if for example, fooBar would just be a property of the Product model, then it would be a matter of extending only the 'Product' model + the changes where it's important (component, adapter), and all other places could be left intact (would just pass extended model).

Can you please give some more context of the required change, so we can better understand it, and make it easier in the future?

In near future, we are considering unifying the payload of our facade services through all the layers in Spartacus, so adding more context to any core logic will be much simplified (basically will come down to the second example, regarding extending the Product model).

Upvotes: 1

Related Questions