2.7.1 • Published 4 months ago

@threefold/grid_http_server v2.7.1

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Http server

Version Lint Build

Http server is an express http server that exposes the functionality of the grid client over http requests.

Installation

External Package

yarn add @threefold/grid_http_server

Local Usage

  • Clone the repository
git clone https://github.com/threefoldtech/tfgrid-sdk-ts.git
  • Install it
yarn install

Configuration

Add network and account's mnemonics in config.json in server directory before running the server.

{
  "network": "<network environment dev, qa or test>",
  "mnemonic": "<your account mnemonics>",
  "storeSecret": "", // secret used for encrypting/decrypting the values in tfkvStore
  "keypairType": "sr25519" // keypair type for the account created on substrate
}

Life cycle

  • User from the outside sends an http post request(with payload) to the HTTP server.
  • Http server checks if there is a post request that its endpoint is registered on the express http server.
  • If this endpoint is registered, the http server will pick up this post request.
  • Http server starts to execute it using the Grid3 client.
  • After finishing the execution, the Http server puts the result back to the user once it's ready.

Running

Locally

yarn start

In External Package

yarn grid_http_server

You can also use another configuration file by using --config or -c option.

 yarn grid_http_server -c pathToConfigFile.json
 # or
 yarn grid_http_server --config pathToConfigFile.json

Usage

All APIs supported can be executed by sending a post request to the server. To execute a method on a module, the module name followed by the method name should be sent on the request endpoint to be like http://localhost:3000/{module}/{method} and the arguments should be sent in request's body.

There is a ping endpoint as well to make sure that the server is up and running http://localhost:3000/ping

Example

This is an example of getting a twin. Put the following content in a file test_twin.ts

import axios from "axios";

async function main() {
  const payload = { id: 1 };
  axios
    .post("http://localhost:3000/twins/get", payload)
    .then(function (response: any) {
      console.log(response);
    })
    .catch(function (error: any) {
      console.log(error.response.data);
    });
}
main();

And then run this file by yarn run ts-node test_twin.ts

see more examples in modules

2.7.0

4 months ago

2.7.1

4 months ago

2.7.0-rc3

4 months ago

2.7.0-rc2

4 months ago

2.7.0-rc1

6 months ago

2.6.4

6 months ago

2.6.3

7 months ago

2.6.2

7 months ago

2.6.1

7 months ago

2.6.0

8 months ago

2.6.0-rc4

8 months ago

2.6.0-rc3

8 months ago

2.6.0-rc1

8 months ago

2.6.0-rc2

8 months ago

2.5.0-rc1

1 year ago

2.5.0-rc2

1 year ago

2.4.3

1 year ago

2.5.0-rc3

1 year ago

2.5.0

1 year ago

2.5.2

12 months ago

2.5.1

1 year ago

2.4.2

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.4.0-rc2

1 year ago

2.4.0-rc1

1 year ago

2.3.5

1 year ago

2.3.4

1 year ago

2.3.2

1 year ago

2.3.3

1 year ago

2.3.1

1 year ago

2.3.0

1 year ago

2.3.0-rc4

1 year ago

2.3.0-rc2

1 year ago

2.3.0-rc3

1 year ago

2.3.0-rc1

1 year ago

2.3.0-alpha12

1 year ago

2.3.0-alpha11

1 year ago

2.3.0-alpha10

1 year ago

2.3.0-alpha9

1 year ago

2.3.0-alpha8

1 year ago

2.3.0-alpha7

1 year ago

2.3.0-alpha6

1 year ago

2.3.0-alpha5

1 year ago

2.3.0-alpha4

2 years ago

2.3.0-alpha3

2 years ago

2.2.0

2 years ago

2.3.0-alpha2

2 years ago

2.2.0-rc6

2 years ago

2.2.0-rc5

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.1.0

2 years ago

2.1.0-rc12

2 years ago

2.1.0-rc2

2 years ago

2.1.0-rc11

2 years ago

2.1.0-rc4

2 years ago

2.1.0-rc10

2 years ago

2.1.0-rc3

2 years ago

2.1.0-rc6

2 years ago

2.1.0-rc5

2 years ago

2.2.0-rc1

2 years ago

2.1.0-rc8

2 years ago

2.1.0-rc7

2 years ago

2.1.0-rc9

2 years ago

2.2.0-rc4

2 years ago

2.2.0-rc3

2 years ago

2.2.0-rc2

2 years ago

2.0.0

2 years ago

2.0.0-rc17

2 years ago

2.0.0-rc15

2 years ago

2.0.0-rc16

2 years ago

2.0.0-rc13

2 years ago

2.0.0-rc14

2 years ago

2.1.0-rc1

2 years ago

2.0.0-rc11

2 years ago

2.0.0-rc12

2 years ago

2.0.0-rc7

2 years ago

2.0.0-rc6

2 years ago

2.0.0-rc5

2 years ago

2.0.0-rc10

2 years ago

4.0.0-rc8.0

2 years ago

2.0.0-rc9

2 years ago

2.0.0-rc8

2 years ago

3.0.0-rc8.0

2 years ago

2.0.0-rc4

2 years ago

2.0.0-rc3

2 years ago

2.0.0-rc2

2 years ago

2.0.0-rc1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago