MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / PostRequest

Method PostRequest

docs/test-csharp-snippets/Module.cs:99–123  ·  view source on GitHub ↗

=== Snippet 6: HTTP Requests - Send ===

(ProcedureContext ctx)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

ToStringUtf8LossyMethod · 0.80
FromStringMethod · 0.45
SendMethod · 0.45
InfoMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected