Skip to content

Commit 2859f4a

Browse files
committed
feat: Implement HTTP gateway with JSON encoding and graph/cell operations
1 parent a3c939e commit 2859f4a

14 files changed

Lines changed: 2249 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,6 @@ perf.data*
126126
/models/
127127
*.onnx
128128
*.onnx_data
129+
130+
131+
nohup.out

Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ version = "0.1.0"
44
authors = ["Hao Shi <shisoftgenius@gmail.com>"]
55
edition = "2021"
66

7+
[workspace]
8+
members = [
9+
"crates/morpheus-http-client",
10+
]
11+
712
[lib]
813
name = "morpheus"
914
path = "src/lib.rs"
@@ -52,6 +57,11 @@ chrono = "0.4"
5257
rayon = "1.10"
5358
fixedbitset = "0.5"
5459

60+
# HTTP gateway (external clients)
61+
axum = { version = "0.7", features = ["json"] }
62+
tower-http = { version = "0.5", features = ["cors"] }
63+
bs58 = "0.5"
64+
5565
# Embedding dependencies
5666
embellama = "0.8.0"
5767
async-trait = "0.1"
@@ -113,4 +123,4 @@ opt-level = 3
113123
debug = true
114124
lto = true
115125
panic = 'unwind'
116-
strip = "none"
126+
strip = "none"

config/server.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server_addr: 127.0.0.1:5403
2+
group_name: MediumMorpheus
3+
meta_members:
4+
- 127.0.0.1:5403
5+
storage:
6+
chunk_count: 32
7+
total_size: "16GB"
8+
backup_storage: null
9+
wal_storage: null
10+
enable_recovery: false
11+
services:
12+
- Cell
13+
- Transaction
14+
- RangedIndexer
15+
- Query
16+
index_enabled: true
17+
tiered_config:
18+
threshold: 0.8
19+
physical_memory_limit: "8GB"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# morpheus-http-client
2+
3+
Async HTTP client for Morpheus' REST gateway.
4+
5+
## Usage
6+
7+
```rust
8+
use morpheus_http_client::{MorpheusHttpClient, CellWriteRequest};
9+
use url::Url;
10+
11+
#[tokio::main]
12+
async fn main() {
13+
let client = MorpheusHttpClient::new(Url::parse("http://127.0.0.1:8080").unwrap())
14+
.with_admin_token("devtoken");
15+
16+
let _ = client.health().await.unwrap();
17+
18+
// Cell CRUD
19+
let cell_id_b58 = "<base58_cell_id>";
20+
let _ = client
21+
.cell_upsert(
22+
cell_id_b58,
23+
&CellWriteRequest {
24+
schema_id: 123,
25+
data: serde_json::json!({"k": "v"}),
26+
},
27+
)
28+
.await
29+
.unwrap();
30+
}
31+
```
32+
33+
## Graph
34+
35+
```rust
36+
use morpheus_http_client::{MorpheusHttpClient, SchemaRef, VertexCreateRequest};
37+
use url::Url;
38+
39+
#[tokio::main]
40+
async fn main() {
41+
let client = MorpheusHttpClient::new(Url::parse("http://127.0.0.1:8080").unwrap())
42+
.with_admin_token("devtoken");
43+
44+
let v = client
45+
.vertex_create(&VertexCreateRequest {
46+
schema: SchemaRef::Name {
47+
schema_name: "people".to_string(),
48+
},
49+
id: None,
50+
data: serde_json::json!({"name": "alice"}),
51+
})
52+
.await
53+
.unwrap();
54+
55+
let _ = client.vertex_get(&v.data.id).await.unwrap();
56+
}
57+
```
58+
59+
## Auth
60+
61+
If the server is configured with `MORPHEUS_HTTP_ADMIN_TOKEN`, this client will send:
62+
63+
`Authorization: Bearer <token>`
64+
65+
when `with_admin_token(...)` is set.
66+
67+
## Data Encoding
68+
69+
The HTTP gateway accepts JSON-native objects and arrays for maps and arrays. For non-JSON
70+
types, use typed values:
71+
72+
```json
73+
{"$type": "u64", "value": 18446744073709551615}
74+
```
75+
76+
Common tags:
77+
- `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`, `f32`, `f64`
78+
- `id` with base58 string value (16-byte id)
79+
- `bytes` with `value` as an array of byte numbers
80+
- `u32[]`, `string[]`, `id[]`, etc.

0 commit comments

Comments
 (0)