=== Snippet 6: HTTP Requests - Send ===
(ProcedureContext ctx)
| 97 | |
| 98 | // === Snippet 6: HTTP Requests - Send === |
| 99 | [SpacetimeDB.Procedure] |
| 100 | public static void PostRequest(ProcedureContext ctx) |
| 101 | { |
| 102 | var request = new HttpRequest |
| 103 | { |
| 104 | Method = SpacetimeDB.HttpMethod.Post, |
| 105 | Uri = "https://example.invalid/upload", |
| 106 | Headers = new List<HttpHeader> |
| 107 | { |
| 108 | new HttpHeader("Content-Type", "text/plain") |
| 109 | }, |
| 110 | Body = HttpBody.FromString("This is the body of the HTTP request") |
| 111 | }; |
| 112 | var result = ctx.Http.Send(request); |
| 113 | switch (result) |
| 114 | { |
| 115 | case Result<HttpResponse, HttpError>.OkR(var response): |
| 116 | var body = response.Body.ToStringUtf8Lossy(); |
| 117 | Log.Info($"Got response with status {response.StatusCode} and body {body}"); |
| 118 | break; |
| 119 | case Result<HttpResponse, HttpError>.ErrR(var e): |
| 120 | Log.Error($"Request failed: {e.Message}"); |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // === Snippet 7: Calling Reducers from Procedures === |
| 126 | // Note: In C#, you can define helper methods that work with the transaction context |
nothing calls this directly
no test coverage detected