πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Sign inDemoInstall
Socket

sylius-shop-api-client

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sylius-shop-api-client

Sylius Shop API JS Client

1.0.2
latest
Source
npm
Version published
Maintainers
1
Created
Source

Sylius Shop API Client

npm npm npm

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"

// Configuration

// Initialize API BaseURL ( Required ) Don't forget trailing /
API_Client.baseURL = "https://my.web.site/api/"


// Set / Clear API Cart Identifier (token), used in all cart requests.

// After Picking Cart => Set token
API_Client.cartToken = "xxxxxxxxxxxxxxx"

// After Dropping Cart => Clear token
API_Client.cartToken = ""


// Set API Locale
API_Client.locale = "en_US"


// Set API default pagination limit
API_Client.limit = "10"


// Set API Default Headers ( Optional ), below values are already defaults.
const myDefaultHeaders = {
  "Accept": "application/json",
  "Content-Type": "application/json",
}
API_Client.defaultHeaders = myDefaultHeaders



// Append New Header (name, value) pair, Any where in your code,
API_Client.appendHeader("Authorization", "Bearer xxxxx")

// Remove header from default headers, Any where in your code,
API_Client.removeHeader("Authorization")


// Set onResponseStatus handler,
// to invoke your custom functions in certain response status codes
API_Client.onResponseStatus = (status) => {

  switch(status){

    case 403:
      // Do something, etc Clear UserData, Remove Auth Headers
      break

    case 500:
      // Do something else
      break

    default:
      // Unhandled cases
      console.log("Unhandled case for status ", status)

  }
}

ShopAPI

import { ShopAPI } from "sylius-shop-api-client"


// Async / Await approach
async loadTaxons() {
  
  try {

    const taxons = await ShopAPI.taxons.show_tree()

    // then use taxon constant

  } catch (error) {

    // handle errors

  }

}

// Callbacks approach
ShopAPI.taxons.show_tree().then((response) => {

// handle response

}).catch((error) => {

  // handle errors

})



Cart ShopAPI.cart

MethodStatus
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

MethodStatus
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

MethodStatus
ShopAPI.taxons.show_treeβœ…
ShopAPI.taxons.show_subtreeβœ…

Checkout ShopAPI.checkout

MethodStatus
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

MethodStatus
ShopAPI.orders.list_ordersβœ…
ShopAPI.orders.order_detailsβœ…

User ShopAPI.user

MethodStatus
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

MethodStatus
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 = {

  // Spread defaults endpoints
  ...ShopAPI,


  // Create your own enpoints using API_client.

  // Get Method, without query params
  myEndpoint: () => API_Client.get("endpoint"),

  // Get Method, query params object (will be converted to string)
  myEndpointCallMethod: (params) => API_Client.get("endpoint", params),

  // Get Method, with changable path and params
  myEndpointPathMethod: (path, params) => API_Client.get(`endpoint/${path}`, params),

  // Post Method, body object (will be stringified inside)
  myEndpointPostMethod: (body) => API_Client.post("endpoint", body),

  // And so on, for put, patch and delete 
  
  

}

// Then use it anywhere in your code,

// Async / Await approach
async loadMyData() {
  
  try {

    const data = await MyShopAPI.myEndpoint()

    // then use data constant

  } catch (error) {

    // handle errors

  }

}

// Callbacks approach
MyShopAPI.myEndpoint().then((response) => {

// handle response

}).catch((error) => {

  // handle errors

})



FAQs

Package last updated on 18 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts