Cosmic Docs

Theme
cs.http

HTTP Client and Server

Provides an API to make HTTP requests and host HTTP servers. HTTPS is supported. There are plans to support WebSockets.

cs.http.get url: string ) string

Makes a GET request and returns the response body text if successful. Returns false if there was a connection error, timeout error (30 secs), or the response code is 5xx. Advanced: cs.http.request

cs.http.getAsync url: string ) Promise

cs.http.post url: string, body: string ) string

Makes a POST request and returns the response body text if successful. Returns false if there was a connection error, timeout error (30 secs), or the response code is 5xx. Advanced: cs.http.request

cs.http.postAsync url: string, body: string ) Promise

cs.http.request url: string, options: ?RequestOptions ) Response

Returns Response object if request was successful. Throws exception if there was a connection or protocol error.

cs.http.requestAsync url: string, options: ?RequestOptions ) runtime.adapter.PromiseSkipJsGen

cs.http.serveHttp host: string, port: number ) object

Starts a HTTP server and returns the handle.

cs.http.serveHttps host: string, port: number, certPath: string, keyPath: string ) object

Starts a HTTPS server and returns the handle.

cs.http.RequestMethod string
"head"
"get"
"post"
"put"
"delete"

cs.http.ContentType string
"json"
"formdata"

cs.http.RequestOptions object
method: RequestMethod
keepConnection: boolean
contentType: ?ContentType
body: ?string
timeout: number
headers: ?object
certFile: ?string

cs.http.Response object
status: number
headers: object
body: string

The response object holds the data received from making a HTTP request.

Provides an interface to the underlying server handle.

cs.http.ServersetHandler callback: function )

Sets the handler for receiving requests.

Request the server to close. It will gracefully shutdown in the background.

Requests the server to close. The promise will resolve when it's done.

cs.http.ServergetBindAddress (  ) runtime.adapter.RtTempStruct(runtime.api.cs_http.Address)

cs.http.Address object
host: string
port: number

Provides an interface to the current response writer.

cs.http.ResponseWritersetStatus status: number )

cs.http.ResponseWritersetHeader key: string, value: string )

cs.http.ResponseWritersend text: string )

Sends UTF-8 text to the response.

cs.http.ResponseWritersendBytes buffer: Uint8Array )

Sends raw bytes to the response.

cs.http.Request object
method: RequestMethod
path: string
data: Uint8Array

Holds data about the request when hosting an HTTP server.