Swift Cloud
RegisterSign In
  • Welcome
  • Join the Beta
  • Platform
    • Web Assembly
    • Compute Runtime
      • Listen for Requests
      • Respond to Requests
  • Console
    • Projects
    • Deployments
    • Domains
    • Origins
    • Dictionaries
    • Metrics
    • Logs
    • Teams
    • Plans & Billing
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Platform
  2. Compute Runtime

Respond to Requests

Responding to HTTP requests is just as simple as listening for them, simply call the various send() methods on the OutgoingResponse object:

import Compute

@main
struct HelloCompute {
    static func main() async throws {
        try await onIncomingRequest(handleIncomingRequest)
    }

    static func handleIncomingRequest(req: IncomingRequest, res: OutgoingResponse) async throws {
        let text = "Hello, World."
        try await res.status(200).send(text)
    }
}

The Compute library provides various versions of send that allow you to pass JSON data, Encodable's, HTML, XML and raw bytes / streams of data.

PreviousListen for RequestsNextProjects

Last updated 2 years ago

Was this helpful?