UNPKG

2.89 kBMarkdownView Raw
1# About
2
3This repository contains a library for interacting with the Aikon marketplace.
4
5It wraps the [Open Rights Exchange protocol](https://github.com/api-market/ore-protocol) to simplify the buying and selling of APIs in the marketplace.
6
7# Usage
8
9## Client
10
11The `apimarket_config.json` is the keyfile which stores the address to connect to the ORE blockchain. It also stores the verifierAuthKey which is used to authrorize verifier to transfer the CPU amount from user's account to API provider's account for the API call. You can download this file from the api.market website.
12
13IMPORTANT: The verifierAuthKey cannot be used for any other functions such as CPU transfer. It can only be used to authrorize verifier.
14
15An example configuration file looks like:
16```json
17{
18 "accountName": "ajscf...",
19 "verifierAuthKey": "U2Fsd...",
20 "verifier": "https...",
21 "verifierAccountName": "verif..."
22}
23```
24
25To call an ORE-enabled API, use the config file, connect to the ORE blockchain and make the request. Here is some fully-functional sample code:
26
27```javascript
28const { ApiMarketClient } = require('@apimarket/apimarket')
29const config = require("apimarket_config.json");
30
31//Setup and connect to the blockchain using your wallet and password in the config
32let apimarketClient = new ApiMarketClient(config);
33await apimarketClient.connect()
34
35// call api - passing in the parameters it needs
36// you specify the api to call using it's unique name registered on the ORE blockchain
37// pass the query parameters as http-url-params and the body parameters as http-body-params if both query and body parameters // exist. Otherwise just pass the parameters to the apimarketClient.fetch directly.
38// example: const params = {"httpBodyParams": {
39// "imageurl": "https://console.cloud.google.com/storage/browser/apimarket-contest-2018-07-1-coffee/10465_full_jpg.jpg"
40// },
41// "httpUrlParams": {
42// "env": "staging"
43// }
44// }
45
46// if only query or body parameters exist, pass them directly to apimarketClient.fetch
47const params = {"imageurl":"https://console.cloud.google.com/storage/browser/apimarket-contest-2018-07-1-coffee/10465_full_jpg.jpg"}
48const response = await apimarketClient.fetch("cloud.hadron.contest-2018-07", params)
49
50//View results
51console.log(response)
52
53```
54
55# Publish NPM Package
56
57PREREQISITE:
58
59Option 1) Use an .npmrc token
60- Include an .npmrc file in the user's root or project root e.g. ~/.npmrc or .../{projectroot}/.npmrc
61- To create an .npmrc file, copy the .npmrc.example file and insert the token (retrieved from LastPass)
62
63OR
64
65Option 2) log-in to npmjs with `npm login` (using account apimarket)
66
67To publish an updated package...
68
69- Update version number in package.json (and example's package.json)
70- `npm publish --tag staging` - to publish staging version
71- `npm publish` - to publish the production version
72
73package name will be: @apimarket/apimarket@{version}