Sylius Shop API Client

Implement Sylius Shop API Client into your app in just One Step!
- Easy to configure API client for quick use
- All API Plugin endpoints are supported!
- Very simple way to add custom endpoints.
- Well-Organized and scalable project.
- All query params, paths and bodies are documented within the code using jsDoc.
Instalation
npm i sylius-shop-api-client
- OR - yarn add sylius-shop-api-client
Usage
API_Client
import { API_Client } from "sylius-shop-api-client"
API_Client.baseURL = "https://my.web.site/api/"
API_Client.cartToken = "xxxxxxxxxxxxxxx"
API_Client.cartToken = ""
API_Client.locale = "en_US"
API_Client.limit = "10"
const myDefaultHeaders = {
"Accept": "application/json",
"Content-Type": "application/json",
}
API_Client.defaultHeaders = myDefaultHeaders
API_Client.appendHeader("Authorization", "Bearer xxxxx")
API_Client.removeHeader("Authorization")
API_Client.onResponseStatus = (status) => {
switch(status){
case 403:
break
case 500:
break
default:
console.log("Unhandled case for status ", status)
}
}
ShopAPI
import { ShopAPI } from "sylius-shop-api-client"
async loadTaxons() {
try {
const taxons = await ShopAPI.taxons.show_tree()
} catch (error) {
}
}
ShopAPI.taxons.show_tree().then((response) => {
}).catch((error) => {
})
Cart ShopAPI.cart
ShopAPI.cart.pick | β
|
ShopAPI.cart.show | β
|
ShopAPI.cart.drop | β
|
ShopAPI.cart.add | β
|
ShopAPI.cart.add_multiple | β
|
ShopAPI.cart.change_quantitiy | β
|
ShopAPI.cart.remove_item | β
|
ShopAPI.cart.shipping_cost | β
|
ShopAPI.cart.add_coupon | β
|
ShopAPI.cart.remove_coupon | β
|
Products ShopAPI.products
ShopAPI.products.by_slug | β
|
ShopAPI.products.by_code | β
|
ShopAPI.products.by_taxon_slug | β
|
ShopAPI.products.by_taxon_code | β
|
ShopAPI.products.reviews_by_slug | β
|
ShopAPI.products.reviews_by_code | β
|
ShopAPI.products.add_review_by_slug | β
|
ShopAPI.products.add_review_by_code | β
|
ShopAPI.products.latest | β
|
Taxons ShopAPI.taxon
ShopAPI.taxons.show_tree | β
|
ShopAPI.taxons.show_subtree | β
|
Checkout ShopAPI.checkout
ShopAPI.checkout.summary | β
|
ShopAPI.checkout.address | β
|
ShopAPI.checkout.get_shipping_methods | β
|
ShopAPI.checkout.set_shipping_method | β
|
ShopAPI.checkout.get_payment_methods | β
|
ShopAPI.checkout.set_payment_method | β
|
ShopAPI.checkout.complete | β
|
Orders ShopAPI.orders
ShopAPI.orders.list_orders | β
|
ShopAPI.orders.order_details | β
|
User ShopAPI.user
ShopAPI.user.request_reset_password | β
|
ShopAPI.user.password_reset | β
|
ShopAPI.user.register | β
|
ShopAPI.user.login | β
|
ShopAPI.user.verify_account | β
|
ShopAPI.user.me | β
|
ShopAPI.user.update_me | β
|
ShopAPI.user.change_password | β
|
Addresses ShopAPI.addresses
ShopAPI.addresses.list | β
|
ShopAPI.addresses.create | β
|
ShopAPI.addresses.update | β
|
ShopAPI.addresses.delete | β
|
ShopAPI.addresses.set_default | β
|
Custom Endpoint Extending
import { ShopAPI, API_Client } from "sylius-shop-api-client"
const MyShopAPI = {
...ShopAPI,
myEndpoint: () => API_Client.get("endpoint"),
myEndpointCallMethod: (params) => API_Client.get("endpoint", params),
myEndpointPathMethod: (path, params) => API_Client.get(`endpoint/${path}`, params),
myEndpointPostMethod: (body) => API_Client.post("endpoint", body),
}
async loadMyData() {
try {
const data = await MyShopAPI.myEndpoint()
} catch (error) {
}
}
MyShopAPI.myEndpoint().then((response) => {
}).catch((error) => {
})