Skip to content

Library Microservice

The lib microservice serves the library assets of the DTaaS platform. Clients use its API endpoints to list and fetch these assets.

This page explains how to use the library microservice.

The assets page describes the suggested storage conventions for library assets.

Assets stored in the library are available in the user workspace.

Application Programming Interface (API)

The lib microservice provides services at two endpoints:

GraphQL API Endpoint: http://intocps.org/lib

HTTP Endpoint: http://intocps.org/lib/files

HTTP protocol

Endpoint: localhost:PORT/lib/files

Enable this endpoint with the -H http.json flag. It provides the usual file upload and download options.

Sample screenshots:

top-level

inside

GraphQL protocol

Endpoint: localhost:PORT/lib

The http://intocps.org/lib URL opens GraphiQL, a GraphQL web page.

GraphiQL shows the query schema and lets you test sample queries. It sends the queries with your DTaaS sign-in, so they work on an installation that requires one. Outside GraphiQL, send GraphQL queries as HTTP POST requests.

The library microservice provides two API calls:

  • List the contents of a directory
  • Fetch a file

Both calls can be sent from GraphiQL or as plain HTTP POST requests. The accepted queries are shown below.

Provide list of contents for a directory

To list the files in a directory, use the following GraphQL query.

Replace the path value with the directory path.

Send requests to: https://intocps.org/lib

GraphQL query for list of contents

query {
  listDirectory(path: "user1") {
    repository {
      tree {
        blobs {
          edges {
            node {
              name
              type
            }
          }
        }
        trees {
          edges {
            node {
              name
              type
            }
          }
        }
      }
    }
  }
}

GraphQL response for list of contents

{
  "data": {
    "listDirectory": {
      "repository": {
        "tree": {
          "blobs": {
            "edges": []
          },
          "trees": {
            "edges": [
              {
                "node": {
                  "name": "common",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "data",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "digital twins",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "functions",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "models",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "tools",
                  "type": "tree"
                }
              }
            ]
          }
        }
      }
    }
  }
}

HTTP request for list of contents

1
2
3
4
5
6
7
8
POST /lib HTTP/1.1
Host: intocps.org
Content-Type: application/json
Content-Length: 388

{
  "query":"query {\n  listDirectory(path: \"user1\") {\n    repository {\n      tree {\n        blobs {\n          edges {\n            node {\n              name\n              type\n            }\n          }\n        }\n        trees {\n          edges {\n            node {\n              name\n              type\n            }\n          }\n        }\n      }\n    }\n  }\n}"
}

HTTP response for list of contents

1
2
3
4
5
6
7
8
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 306
Content-Type: application/json; charset=utf-8
Date: Tue, 26 Sep 2023 20:26:49 GMT
X-Powered-By: Express
{"data":{"listDirectory":{"repository":{"tree":{"blobs":{"edges":[]},"trees":{"edges":[{"node":{"name":"data","type":"tree"}},{"node":{"name":"digital twins","type":"tree"}},{"node":{"name":"functions","type":"tree"}},{"node":{"name":"models","type":"tree"}},{"node":{"name":"tools","type":"tree"}}]}}}}}}

Fetch a file from the available files

This query takes a file path and returns the contents of the file.

To try this query, create a file files/user2/data/welcome.txt containing hello world.

GraphQL query for fetch a file

query {
  readFile(path: "user2/data/welcome.txt") {
    repository {
      blobs {
        nodes {
          name
          rawBlob
          rawTextBlob
        }
      }
    }
  }
}

GraphQL response for fetch a file

{
  "data": {
    "readFile": {
      "repository": {
        "blobs": {
          "nodes": [
            {
              "name": "welcome.txt",
              "rawBlob": "hello world",
              "rawTextBlob": "hello world"
            }
          ]
        }
      }
    }
  }
}

HTTP request for fetch a file

1
2
3
4
5
6
7
POST /lib HTTP/1.1
Host: intocps.org
Content-Type: application/json
Content-Length: 217
{
  "query":"query {\n  readFile(path: \"user2/data/welcome.txt\") {\n    repository {\n      blobs {\n        nodes {\n          name\n          rawBlob\n          rawTextBlob\n        }\n      }\n    }\n  }\n}"
}

HTTP response for fetch a file

1
2
3
4
5
6
7
8
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 134
Content-Type: application/json; charset=utf-8
Date: Wed, 27 Sep 2023 09:17:18 GMT
X-Powered-By: Express
{"data":{"readFile":{"repository":{"blobs":{"nodes":[{"name":"welcome.txt","rawBlob":"hello world","rawTextBlob":"hello world"}]}}}}}

The path is the file path to look at. For example, user1 looks at the files of user1, and user1/functions looks at the contents of the functions/ directory.