- Introduction
- Prerequisites
- Setup
- Usage
- API Endpoints
- Logs
- Test the API
- Requests with Curl
- Requests with Javascript
- Troubleshooting
- Contributing
- License
This project sets up a Docker container running the TFGrid SDK HTTP server, which provides an API for interacting with the ThreeFold Grid.
- Docker
- Docker Compose
-
Clone this repository:
git clone https://github.com/Mik-TF/grid_http_server_docker cd grid_http_server_docker
-
Create a
config.json
file in the project root with your configuration.cp config.json.template config.json
You can use the file
config.json.template
as a template. Here is an example:{ "network": "dev", "mnemonic": "your TFGrid mnemonic here", "storeSecret": "some-secret", "keypairType": "sr25519" }
Replace the values with your actual configuration.
-
Build the Docker image:
docker buildx build -t grid_http_server .
-
Start the server:
docker compose up -d
-
The server will be available at
http://localhost:3000
-
To stop the server:
docker compose down
The server exposes several endpoints for interacting with the ThreeFold Grid. Here are some examples:
GET /
: Health checkPOST /twins
: Create a new twinGET /twins/:twinId
: Get twin informationPOST /contracts
: Create a new contractGET /contracts/:contractId
: Get contract information
For a full list of endpoints and their usage, please refer to the TFGrid SDK documentation.
To view the server logs:
docker compose logs -f grid3_client
Once you set up the API, you can test it with a basic ping-pong request:
http://localhost:3000/ping
This in a browser should return pong
.
You can also use curl:
curl http://localhost:3000/ping
- Ping the server:
curl http://localhost:3000/ping
- Create a farm:
curl -X POST http://localhost:3000/farms/create \
-H "Content-Type: application/json" \
-d '{"name": "MyNewFarm", "publicIps": []}'
- Get farm info by farm ID:
curl http://localhost:3000/farms/getFarmByID \
-H "Content-Type: application/json" \
-d '{"id": 1}'
- Install axios
npm install axios
- Create a farm
- File name:
createFarm.ts
- File content:
const axios = require('axios'); async function createFarm() { try { const response = await axios.post('http://localhost:3000/farms/create', { name: "farm1230" }); console.log('Farm created:', response.data); } catch (error) { console.error('Error creating farm:', error.response?.data || error.message); } } createFarm();
- File name:
- Run the file
node ./scripts/createFarm.ts
The deployment script will ask you for the deployment parameters.
- Deploy the VM
node ./scripts/deployVm.ts
- See help menu
node ./scripts/deployVm.ts -h
- Delete the deployment
node ./scripts/deployVm.ts --delete
- If you encounter permission issues with the
config.json
file, ensure it has the correct read permissions. - If the server isn't accessible, check that port 3000 isn't being used by another application.
Contributions are welcome! Please feel free to submit a Pull Request.
This repo is under the Apache 2.0 license.