@@ -10,27 +10,56 @@ I have intentionally only implemented mainly support for node as I don't see the
1010
1111The readme is a WIP and the code could probably have some error handling added.
1212
13- ## Example
13+ ## Usage
1414
1515Below is an example of how to use this to interact with the API for the custom types, it gets a type and writes the result to ta json file.
1616
17+ ### If using commonJS:
18+
1719``` js
18- const Api = require (' ./dist/index ' ). default ;
20+ const Api = require (' @reecem/custom-type-api ' ) ;
1921const credentials = require (' ./env.json' );
2022const fs = require (' fs' );
2123const path = require (' path' )
2224
23-
2425const api = new Api (' slicemachine-startup' , credentials .token )
2526
2627async function test () {
27- await api .login ()
28+ await api .init ()
29+
30+ try {
31+ const type = await api .types ().getOne (' page' );
32+
33+ console .log (type)
34+
35+ fs .writeFileSync (path .join (__dirname , ' page.json' ), JSON .stringify (type, null , 2 ))
36+ } catch (ex) {
37+ console .error (ex)
38+ }
39+ }
40+
41+ test ()
42+ ```
43+
44+
45+ ### If using modules:
46+
47+ ``` js
48+ import Api from ' @reecem/custom-type-api'
49+
50+ import { createRequire } from " module" ; // Bring in the ability to create the 'require' method
51+ const require = createRequire (import .meta.url); // construct the require method
52+ const credentials = require (' ../env.json' );
53+
54+ async function test () {
55+ const api = new Api (' slicemachine-startup' , credentials .token )
56+
57+ await api .init ()
2858
2959 try {
30- const response = await api .types ().getOne (' page' );
31- const res = await response .json ();
32- console .log (res)
33- fs .writeFileSync (path .join (__dirname , ' page.json' ), JSON .stringify (res, null , 2 ))
60+ let slice = await api .slices ().getOne (' form_slice' );
61+ console .log (slice)
62+ fs .writeFileSync (path .join (__dirname , ' form_slice.json' ), JSON .stringify (slice, null , 2 ))
3463 } catch (ex) {
3564 console .error (ex)
3665 }
0 commit comments