0% found this document useful (0 votes)
17 views1 page

EdgeStore API Reference Guide

The document provides a comprehensive reference for the EdgeStore API, detailing both RPC and REST APIs for interacting with the EdgeStore node. It includes methods for retrieving the version, status, and peers of the node, as well as uploading and retrieving data and files. Additionally, it outlines the HTTP server for file serving, including how to access files using their keys and relative paths.

Uploaded by

anayawork158
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

EdgeStore API Reference Guide

The document provides a comprehensive reference for the EdgeStore API, detailing both RPC and REST APIs for interacting with the EdgeStore node. It includes methods for retrieving the version, status, and peers of the node, as well as uploading and retrieving data and files. Additionally, it outlines the HTTP server for file serving, including how to access files using their keys and relative paths.

Uploaded by

anayawork158
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

API References

EdgeStore API Reference


The EdgeStore node provides two set of APIs, namely, the RPC APIs and the REST APIs. The
RPC APIs are mostly for interacting with the EdgeNode, e.g. query node state, upload/retrieve
files. The REST APIs are primarily for content serving, e.g. serving a PNG image file or a PDF
file. Below we provide the reference for these APIs.

Table of Contents

1. RPC APIs
i. GetVersion: get EdgeStore version
ii. GetStatus: get EdgeStore status
iii. GetPeers: get EdgeStore peers
iv. PutData: upload text data string
v. GetData: retrieve text data string
vi. PutFile: upload file/directory
vii. GetFile: retrieve file/directory
2. REST APIs
i. File: file serving

RPC APIs
We can interact with the EdgeStore node through its RPC API. The RPC server runs at port
19888 by default. It can be changes through the [Link] config in the [Link] file.

GetVersion

This API returns the version of the EdgeStore node.

method: [Link]

returns: the version, git commit hash, and build time of the EdgeStore node.

Example

# Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[],"id":1}'

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"version": "0.0.1",
"git_hash": "cf19ef60221f4b4ca70c9c2b55e6682930deb1ea",
"timestamp": "Sun Feb 6 19:59:07 UTC 2022"
}
}

GetStatus

This API returns the status of the EdgeStore node.

method: [Link]

returns: the status of the EdgeStore node, including its ID.


!
Example

# Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[],"id":1}'

# Result
! {
"jsonrpc": "2.0",
"id": 1,
"result": {
! "id": "0x3181485069e7f93f1EF83cA6F58dD07318291179",
"current_time": "1644180133"
!
}
}

GetPeers

This API returns the peers of the EdgeStore node.

method: [Link]

returns: the IDs of the peers the EdgeStore node is currently connected to.

Example

# Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[],"id":1}'

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"peers": ["0x018132E076089494861983ba5df4D89450a6b9cF", "0xD1a42E20b586784FC04587eB96c7249C03d68DDa"
}
}

PutData

This API allows a user to upload data (as a text string) to the EdgeStore network. The API
returns the key for data retrieval.

method: [Link]

returns: the key for retrieving the uploaded data

Example

# Request: put data as a text string


curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[{"val": "Hello World"}],"id":1}'

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"key": "0x022d5ed71ca8f872cc2a3a34976aaad77be8e18ee50268c213abed79e113c618"
"success": true
}
}

GetData

This API allows a user retrieve the text data with the key.

method: [Link]

returns: the uploaded text data associated with the key

# Request: get data with the key returned by PutData


curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[{"key": "0x022d5ed71ca8f872cc2a3a34976aa

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"val": "Hello World"
}
}

PutFile

This API allows a user to upload a file or a directory the EdgeStore network. The API returns
the key for the file/directory retrieval. Note that the directory to be uploaded can have multiple
levels of sub-directories. It will be processed recursively.

method: [Link]

returns: the key for retrieving the uploaded data

Example 1: Upload a file

# Request: upload a file


curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[{"path": "theta-edge-store-demos/demos/i

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"key": "0xbc0383809da9fb98c5755e3fa4f19f4ebc7e34308ab321246e4bb54e548fad04"
"relpath": "smiley_explorer.png",
"success": true
}
}

Example 2: Upload a directory with files (or even subdirectories) under it

# Request: upload a directory of files. The directory can have multiple levels of sub-directories. It will be processed recursively.
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[{"path": "theta-edge-store-demos/demos/i

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"key": "0xdacc9a23035a458f21aa0cb51189d715cb5c43d7ff4c0227cca5c25eeef3d5b4"
"relpath": "data",
"success": true
}
}

GetFile

This API allows a user retrieve the file/directory with the key. The API returns the path of the
downloaded file/directory. In the case of directory retrival, this API will fetch and reassemble
the directory with all the files and sub-directories underneath it.

method: [Link]

returns: the uploaded text data associated with the key

Example 1: Retrieve a file

# Rquest: retrieve a file (the smiley_explorer.png file we uploaded earlier)


curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[{"key": "0xbc0383809da9fb98c5755e3fa4f19

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"path": "../data/edgestore/playground/single-node-network/node/storage/file_cache/0xbc0383809da9fb98c5755e3fa4f19f4ebc7e34308ab321246e4bb54e548fa
}
}

Example 2: Retrieve a directory and all the files/sub-directories under it.

# Retrieve a directory. This will retrieve and reassemble the directory (all the files and sub-directories). The API returns the path of the reassembled
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"[Link]","params":[{"key": "0xdacc9a23035a458f21aa0cb51189d

# Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"path": "../data/edgestore/playground/single-node-network/node/storage/file_cache/0xdacc9a23035a458f21aa0cb51189d715cb5c43d7ff4c0227cca5c25eeef3d
}
}

REST APIs
In addition to the RPC server, the EdgeStore also runs an HTTP server to for file serving. The
HTTP server runs at port 8080 by default. It can be changes through the [Link] config in
the [Link] file.

The File API

This API is used for file serving. The file can be retrieved by its key and its relative path.

method: GET

resource: file

base route: api/v1/file

query parameters: api/v1/file?key=<key>&relpath=<relpath>&pathonly=<true|false>

key : A string, the key for the file/directory, e.g.


0xdacc9a23035a458f21aa0cb51189d715cb5c43d7ff4c0227cca5c25eeef3d5b4

relpath : A string, the relative path of the file to be retrieved. If the file was uploaded as
an individual file, the relpath should be the same as the file name, e.g.
smiley_explorer.png . If the file was uploaded as part of a directory, the relpath should
be the relative path to the file from the directory, e.g., data/theta_network.jpg . Please
see the examples below for more details.
pathonly : A boolean flag indicating whether to return the path of the file or the file
content

examples:

browser link: [Link]


key=0xdacc9a23035a458f21aa0cb51189d715cb5c43d7ff4c0227cca5c25eeef3d5b4&rel
path=data/theta_network.jpg
curl command: curl "[Link]
key=0xdacc9a23035a458f21aa0cb51189d715cb5c43d7ff4c0227cca5c25eeef3d5b4&relpath=d
ata/theta_network.jpg&pathonly=true"

Common questions

Powered by AI

The RPC APIs in Theta EdgeStore are primarily used for interacting with the EdgeNode, which involves operations such as querying node status, uploading, and retrieving data. Specifically, methods like GetVersion and GetStatus provide details about the EdgeStore version and its operational status, respectively. Uploads and retrievals of text data and files are other key functionalities facilitated through methods like PutData and GetData . On the other hand, REST APIs are designed mainly for content serving. They serve files by retrieving them by their keys and relative paths, helping in direct user access over HTTP protocols . These two sets of APIs together offer a comprehensive interface for both backend data management and user-facing content delivery.

The EdgeStore API maintains file integrity through its RPC API by associating a unique key to each uploaded file or directory. When files are uploaded using the PutFile method, a key is generated which acts as a reference to access the file later through methods like GetFile. This key-based retrieval system ensures that the data accessed is exactly what was uploaded, as any data modifications would result in a mismatch of keys . Additionally, directory uploads ensure that all files and subdirectories are processed recursively and can be accurately reconstructed, validating whole-tree integrity .

The GetStatus method queries the status of a Theta EdgeStore node, returning useful information such as the node's ID and current operational time, which helps in monitoring the node's activity and health . Meanwhile, the GetPeers method provides a list of peer nodes that the queried node is connected to. This facilitates network topology mapping, troubleshooting, and optimization by allowing administrators to understand node connectivity and peer interactions within the EdgeStore. Together, these methods equip users with the information needed for effective network maintenance and scaling .

The concurrent operation of HTTP and RPC servers in Theta EdgeStore offers significant advantages for large-scale decentralized content delivery networks. This dual-server setup ensures that both internal network operations (via RPC) and external content access (via HTTP) can be handled simultaneously without performance bottlenecks. Such a configuration enhances scalability and reliability, allowing efficient handling of data requests and distribution across a potentially vast user base. This separation of responsibilities facilitates more stable, manageable network traffic profiles, aligning with the high-demand requirements of large-scale content delivery .

The Theta EdgeStore utilizes the key parameter to reconstruct complex file structures during directory retrieval by associating a unique key with the whole directory upon upload. When retrieved, the GetFile method uses this key to fetch and reassemble the entire directory structure, including all files and nested subdirectories, accurately restoring the original hierarchy. This functionality is crucial as it ensures data consistency and integrity, preserving the context and relationships between files which is essential in scenarios like software repositories or multi-file datasets, where the structure impacts usability and data analysis .

The Theta EdgeStore supports the uploading of directories (including multiple levels of subdirectories), which significantly enhances its functionality. This capability enables the storage of complex data structures in a single operation, maintaining their internal hierarchy and relationships. By doing so, EdgeStore can reconstruct the exact structure during retrieval, allowing for processes that require complete data environments, such as batch processing or data analysis. This is a marked improvement over systems limited to single file uploads, which necessitate manual effort to preserve the context and structure of multiple related files, reducing efficiency and increasing the potential for error .

The PutData method in the Theta EdgeStore API allows users to upload data in the form of a text string into the network. Upon successful upload, the method returns a key that acts as a unique identifier for the uploaded data. This key is essential for the subsequent retrieval of the data through the GetData method, ensuring that users can access their data reliably and verifiably. It essentially creates a direct, secure linkage between the data stored and its retrieval mechanism, thereby enhancing data management and accessibility within the EdgeStore ecosystem .

The Theta EdgeStore API's file serving functionality through REST APIs enhances user accessibility by providing a straightforward HTTP interface for accessing files. Users can specify keys and relative paths to retrieve files via HTTP GET requests, which are common and well-supported across various platforms and languages. This approach simplifies integration into existing web applications and services. Additionally, it includes options like the 'pathonly' parameter, which allows users to control the extent of information retrieved, optimizing bandwidth usage and processing time. Such features make content management more efficient and accessible for diverse user requirements and environments .

Using EdgeStore's JSON-RPC API offers strategic advantages such as seamless integration for developers working with blockchain and decentralized applications (dApps). The JSON-RPC interface provides consistency and familiarity for developers accustomed to JSON-based operations, facilitating easier adoption and integration. It allows precise and flexible data operations such as uploading, retrieving, and querying nodes, which are crucial for dApp functionalities. This direct method of interaction aligns well with the decentralized ethos by enabling applications to engage with blockchain data without centralized intermediary systems, enhancing application efficiency and user control over data operations .

The Theta EdgeStore allows for the customization of its HTTP and RPC servers primarily by adjusting the ports they operate on, which can be modified in the config.yaml file. The default port for the RPC server is 19888 and for the HTTP server, it is 8080. This flexibility in configuration is crucial as it allows network operators to adjust their setups in order to avoid port conflicts with other running services and to optimize network traffic for different environments, such as development or production environments .

You might also like