Skip to content

Commit 234f1bf

Browse files
author
Crhistian Ramirez
committed
✏️ update readme
1 parent 29b8453 commit 234f1bf

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The OrderCloud SDK for Javascript is a modern client library for building solutions targeting the [Ordercloud eCommerce API](https://developer.ordercloud.io/documentation). The SDK aims to greatly improve developer productivity and reduce errors.
44

55
- [Features](#-features)
6+
- [Requirements](#requirements)
67
- [Installation](#%EF%B8%8F-installation)
78
- [Adding it to your project](#-adding-it-to-your-project)
89
- [Using named imports](#using-named-imports)
@@ -11,11 +12,15 @@ The OrderCloud SDK for Javascript is a modern client library for building soluti
1112
- [Authentication](#-authentication)
1213
- [Filtering](#-filtering)
1314
- [Impersonation](#-impersonation)
15+
- [Configuration](#configuration)
16+
- [Handling Errors](#handling-errors-)
17+
- [Interceptors](#interceptors)
18+
- [Cancelling Requests](#cancelling-requests)
19+
- [Async/Await](#asyncawait)
1420
- [Typescript Support](#typescript-support)
1521
- [Understanding OrderCloud's models](#understanding-orderclouds-models)
1622
- [Strongly Typed xp](#strongly-typed-xp)
1723
- [Typescript utilities](#typescript-utilities)
18-
- [Handling Errors](#handling-errors-)
1924
- [License](#-license)
2025
- [Contributing](#-contributing)
2126
- [Getting Help](#-getting-help)
@@ -200,6 +205,7 @@ Simply set the options you need to override and the SDK will merge it with the d
200205
import { Configuration } from 'ordercloud-javascript-sdk';
201206

202207
Configuration.Set({
208+
baseApiUrl: 'https://sandboxapi.ordercloud.io',
203209
timeoutInMilliseconds: 20 * 1000
204210
})
205211
```
@@ -225,7 +231,7 @@ Products.Get('my-product')
225231
// that falls outside of the range of 2xx, the error will be of type OrderCloudError
226232
// https://ordercloud-api.github.io/ordercloud-javascript-sdk/classes/orderclouderror
227233
console.log(error.message);
228-
console.log(error.errors);
234+
console.log(JSON.stringify(error.errors, null, 4));
229235
} else if (error.request) {
230236
// the request was made but no response received
231237
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js
@@ -288,6 +294,42 @@ Products.List({search: 'Tennis balls'}, {cancelToken: signal.token})
288294
signal.cancel('This request was cancelled!')
289295
```
290296

297+
## Async/Await
298+
Async/Await is a special syntax to work with promises in a more comfortable fashion. Because the SDK is built with promises the syntax works right out of the box - simply add the `async` keyword to your outer function method.
299+
300+
```javascript
301+
// with normal promises
302+
(() => {
303+
Auth.Login('myusername', 'mypassword', 'myclientID', ['FullAccess'])
304+
.then(authResponse => {
305+
Tokens.SetAccessToken(authResponse.access_token)
306+
Me.ListOrders().then(orderList => {
307+
const firstOrder = orderList.Items[0]
308+
console.log(firstOrder.Total)
309+
})
310+
})
311+
.catch(err => {
312+
console.log(err)
313+
})
314+
})()
315+
```
316+
317+
```javascript
318+
// with async/await
319+
(async () => {
320+
try {
321+
const authResponse = await Auth.Login('myusername', 'mypassword', 'myclientID', ['FullAccess'])
322+
Tokens.SetAccessToken(authResponse.access_token)
323+
const myOrders = await Me.ListOrders()
324+
const firstOrder = myOrders.Items[0]
325+
} catch (err) {
326+
console.error(err)
327+
}
328+
})()
329+
```
330+
331+
> NOTE: async/await is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers without first transpiling to ES5 so use with caution.
332+
291333
## Typescript Support
292334

293335
While Typescript is not required to use this project (we compile it down to ES5 javascript for you), it does mean there are some added benefits for our Typescript users. You will need a minimum of typescript version 3.5 for all features to work correctly.

0 commit comments

Comments
 (0)