Blog • Announcements | Developer

New Moltin JavaScript request client

Last updated: 24 Jun 2019
Today we are excited to share with you a new lightweight JavaScript client that puts the power in your hands.

The library was built with simplicity in mind and was designed to abstract the common things we see developers doing when using Moltin.

We needed a way to generate an authentication token, make a request with that token and return the response in JSON, without having to worry about the mechanics involved.

The new Moltin JavaScript client is perfect when developing client-side applications and for extending Moltin with webhooks inside a serverless function.

Overview

The new @moltin/request library exports only 6 functions:

  • get()
  • post()
  • put()
  • delete()
  • authenticate()
  • createCartIdentifier()

You will most likely always be using get() and post() on within your client application to get products and post to cart and checkout. While interacting with creating, updating and deleting resources on the server side, either inside an application or a serverless function.

To get started with the library, you will want to install via Yarn or NPM.

 

yarn add @moltin/request # npm install --save @moltin/request

Once you have the dependency installed, you can now import the library and instantiate a new client.

const { createClient } = require('@moltin/request')
const client = new createClient({
client_id: '...'
})

How to use

You can find all the available functions and parameters over at GitHub along with some example client and server applications that show just how easy it is to import and connect with your existing applications.

If we wanted to get all products, it's as simple as:

 

const { createClient } = require('@moltin/request')
// import { createClient } from '@moltin/request'
const client = new createClient({
client_id: '...'
})
client
.get('products')
.then(console.log)
.catch(console.error)

It's just as easy to get a product by ID:

const { createClient } = require('@moltin/request')
// import { createClient } from '@moltin/request'
const client = new createClient({
client_id: '...'
})
client
.get('products/:id')
.then(console.log)
.catch(console.error)

If you have any feedback, please reach out via the forum or over on GitHub issues.

From Our Blog

20 Jun 2019

Analytics for your Moltin store

Today we’re going to take a look at how to use best-in-class data warehousing and analytics solutions on top of Moltin, specifically in relation to orders and order items.

Read More
author
Matt Foyle
9 min. read in Developer
19 Jun 2019

Further Flows improvements

We've been working hard recently to improve the developer experience when using the Moltin API to build an online store.

Read More
author
James Owers
9 min. read in Announcements | Developer
29 May 2019

What to consider when migrating eCommerce platforms

Even though you are well aware of the pitfalls of your current eCommerce platform - be it rigidity, technical debt or the inability to innovate quickly; the thought of re-platforming can be a scary...

Read More
author
Joanna Suau
9 min. read in Magento Migration | Developer | eCommerce