|
| 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