From 56876eb963b0795ffce1bb872687695562b8491e Mon Sep 17 00:00:00 2001 From: Linda Nguyen <92531748+lindot11@users.noreply.github.com> Date: Sat, 23 Sep 2023 21:47:59 +0200 Subject: [PATCH 1/4] updated documentation for http queries in servers/lib/README.md --- servers/lib/README.md | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/servers/lib/README.md b/servers/lib/README.md index e5b38c32f..11487d1d8 100644 --- a/servers/lib/README.md +++ b/servers/lib/README.md @@ -213,3 +213,103 @@ query { } } ``` + +## HTTP API Calls + +The GraphQL queries can be sent as HTTP post queries over the same API connection. + +Samples of the lib microservice HTTP requests and responses are given here. +### Directory listing + +``` +POST /lib HTTP/1.1 +Host: localhost:4001 +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}" +} +``` + +``` +{ + "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 +``` +POST /lib HTTP/1.1 +Host: localhost:4001 +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}" +} +``` + +``` +{ + "data": { + "readFile": { + "repository": { + "blobs": { + "nodes": [ + { + "name": "sample.txt", + "rawBlob": "hello world", + "rawTextBlob": "hello world" + } + ] + } + } + } + } +} +``` From ebda3407e135c93a8e64c668403072d387e62d8b Mon Sep 17 00:00:00 2001 From: Linda Nguyen <92531748+lindot11@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:00:16 +0200 Subject: [PATCH 2/4] Added GraphQL API Calls and HTTP API Calls section --- docs/admin/servers/lib/LIB-MS.md | 239 +++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) diff --git a/docs/admin/servers/lib/LIB-MS.md b/docs/admin/servers/lib/LIB-MS.md index eb4126d1f..903e327ad 100644 --- a/docs/admin/servers/lib/LIB-MS.md +++ b/docs/admin/servers/lib/LIB-MS.md @@ -103,3 +103,242 @@ Users can access the library microservice at URL: `http://localhost:/lib`. The URL endpoint for this microservice is located at: `localhost:PORT/lib` +## GraphQL API Calls + +The lib microservice supports two GraphQL queries. + +### Directory Listing + +#### Query: +To retrieve a list of files in a directory, use the following GraphQL query. Replace `path` with the desired directory path. +``` +query { + listDirectory(path: "user1") { + repository { + tree { + blobs { + edges { + node { + name + type + } + } + } + trees { + edges { + node { + name + type + } + } + } + } + } + } +} +``` +#### Response: +This query returns the list of files and subdirectories in the specified directory. The response will include the name and type of each item. + +``` +{ + "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" + } + } + ] + } + } + } + } + } +} +``` +### Fetching a File + +#### Query: +To retrieve the contents of a file, use the following GraphQL query. Replace `path` with the desired file path. + +```graphql +query { + readFile(path: "user2/data/sample.txt") { + repository { + blobs { + nodes { + name + rawBlob + rawTextBlob + } + } + } + } +} +``` + +#### Response: +This query returns the name, raw binary blob, and raw text blob of the specified file. The `rawBlob` field contains the file contents in binary format, while the `rawTextBlob` field contains the file contents as plain text. + +```graphql +{ + "data": { + "readFile": { + "repository": { + "blobs": { + "nodes": [ + { + "name": "sample.txt", + "rawBlob": "hello world", + "rawTextBlob": "hello world" + } + ] + } + } + } + } +} +``` +## HTTP API Calls + +The lib microservice also supports making API calls using HTTP POST requests. Simply send a POST request to the URL endpoint with the GraphQL query in the request body. Make sure to set the Content-Type header to "application/json". + +Here are examples of the HTTP requests and responses for the GraphQL API calls. +### Directory Listing + +#### Request: +``` +POST /lib HTTP/1.1 +Host: localhost:4001 +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}" +} +``` + +#### Response: +``` +{ + "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" + } + } + ] + } + } + } + } + } +} +``` +### Fetching a File + +#### Request: +``` +POST /lib HTTP/1.1 +Host: localhost:4001 +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}" +} +``` + +#### Response: +``` +{ + "data": { + "readFile": { + "repository": { + "blobs": { + "nodes": [ + { + "name": "sample.txt", + "rawBlob": "hello world", + "rawTextBlob": "hello world" + } + ] + } + } + } + } +} +``` + From a1625bd08afb948823c3c75b06b8938b120e07b5 Mon Sep 17 00:00:00 2001 From: Linda Nguyen <92531748+lindot11@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:08:36 +0200 Subject: [PATCH 3/4] Made a better description for HTTP API Calls --- servers/lib/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servers/lib/README.md b/servers/lib/README.md index 11487d1d8..f1fa74f52 100644 --- a/servers/lib/README.md +++ b/servers/lib/README.md @@ -215,10 +215,10 @@ query { ``` ## HTTP API Calls +The lib microservice also supports making API calls using HTTP POST requests. Simply send a POST request to the URL endpoint with the GraphQL query in the request body. Make sure to set the Content-Type header to "application/json". -The GraphQL queries can be sent as HTTP post queries over the same API connection. +Here are examples of the HTTP requests and responses for the GraphQL API calls. -Samples of the lib microservice HTTP requests and responses are given here. ### Directory listing ``` From 8bdebe072cfa572cb21ec7c969b3dd02553cf407 Mon Sep 17 00:00:00 2001 From: Linda Nguyen <92531748+lindot11@users.noreply.github.com> Date: Sun, 24 Sep 2023 01:24:01 +0200 Subject: [PATCH 4/4] prettified json format in HTTP requests --- docs/admin/servers/lib/LIB-MS.md | 4 ++-- servers/lib/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/admin/servers/lib/LIB-MS.md b/docs/admin/servers/lib/LIB-MS.md index 903e327ad..868edf9f1 100644 --- a/docs/admin/servers/lib/LIB-MS.md +++ b/docs/admin/servers/lib/LIB-MS.md @@ -253,7 +253,7 @@ 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}" + "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}" } ``` @@ -317,7 +317,7 @@ 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}" + "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}" } ``` diff --git a/servers/lib/README.md b/servers/lib/README.md index f1fa74f52..a222ceb5e 100644 --- a/servers/lib/README.md +++ b/servers/lib/README.md @@ -228,7 +228,7 @@ 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}" + "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}" } ``` @@ -290,7 +290,7 @@ 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}" + "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}" } ```