• Log in
  • Sign up
  • Contact Us

Get in touch  

Blog • Announcements | Developer

New Moltin JavaScript request client

Last updated: 03 Jul 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

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


const { MoltinClient } = require('@moltin/request')
const moltin = new MoltinClient({
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 { MoltinClient } = require('@moltin/request')
// import { MoltinClient } from '@moltin/request'
const client = new MoltinClient({
client_id: '...'
})
client
.get('products')
.then(console.log)
.catch(console.error)

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

const { MoltinClient } = require('@moltin/request')
// import { MoltinClient } from '@moltin/request'
const client = new MoltinClient({
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

11 Sep 2019

An Introduction to eCommerce APIs

In this post we’ll cover what an eCommerce API is, why you should use one and how you should evaluate an eCommerce API.

Read More
author
Adam Sturrock
in Developer | eCommerce
21 Aug 2019

Systems quotas to protect your store

Today we are introducing fair usage quotas within our architecture. The use of quotas is common practice for web facing services and their introduction by Moltin is to ensure an optimal and fair...

Read More
author
Jonathan Prest
in Announcements | Developer
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