The Moltin React SDK is a simple to use interface for the Moltin eCommerce API to help you get off the ground quickly and efficiently within client and server applications.
moltin-react
is a React-friendly derivation of Moltin's js-sdk package that makes full use of React's feature set.
📚 API v1 docs — 📚 API v2 (pre-release) docs — 📚 moltin.com
This package is generally functional but does not currently have full code coverage. Endpoints currently available are:
- Brands
- Cart
- Categories
- Collections
- Currencies
- Gateways
- Orders
- Products
- Settings
- Modifiers - available via
Moltin.Products
- Customers
- Addresses
- Taxes
- Shipping
- Promotions
- Flows
- Entries
- Fields
- Email Templates
- Webhooks
- Images
- Files
npm install --save moltin-react
import { MoltinClient } from 'moltin-react';
const Moltin = MoltinClient({
clientId: 'XXX'
});
// Authenticate the client
Moltin.Authenticate().then((response) => {
console.log('authenticated', response);
});
moltin-react
exports a named object with the above MoltinClient
instantiator, as well as an uninstantiated Moltin
class, so the client can also be instantiated as a constructor:
import moltin from 'moltin-react'; // NOTE: unnamed import
const Moltin = new moltin({
clientId: 'XXX'
});
// same as option A from here on out
Moltin.Authenticate().then((response) => {
console.log('authenticated', response);
});
Note: This requires a Moltin account.
Once created, Moltin
in the above example conforms to the standard Moltin JS documentation. Check out the Moltin wiki to learn more about authenticating and the available endpoints.
On creation, either of the above options takes an identical configuration object, which requires only clientId
(see Authentication) but which can accept any of the following:
FORMAT: /* <key> // [<default value>], <comment> */
{
clientId, // required
clientSecret, // API Secret. Don't utilize unless you're rendering on server.
currency,
debug, // [false]
language, // [false]
version // ['v1'], API version; also accepts 'v2', which, again, is currently unavailable.
}
If you're using webpack, you'll need to add the following to webpack.config.js
or webpack configuration equivalent:
node: {
fs: 'empty'
}
This is a temporary patch and will eventually be replaced with a more react-friendly alternative (see Roadmap).
As previously stated, moltin-react
is pre-release but still usable. Here's what's coming down the pike:
- full API v1 support
- flux/redux integration
- roll-your-own storage manager
- separation of
localStorage
into modular storage engine - higher-order components
The SDK is built with ES6 modules that are bundled into Node and browser compatible files using Rollup.
If you want to roll your own bundle, or make changes to any of the modules in src
, then you'll need to install the package dependencies and build the dist
files.
npm install
npm run build
You can learn more about Rollup, the API and configuration here.