src/nodejs/jssynchttpclient

Example: cmd: -r:off

import src/nodejs/jssynchttpclient
from std/uri import parseUri, Uri

let client: JsHttpClient = newJsHttpClient()
const data = """{"key": "value"}"""

block:
  let url: Uri = parseUri("https://google.com")
  let content: cstring = client.getContent(url)

block:
  let url: Uri = parseUri("https://httpbin.org/delete")
  let content: cstring = client.deleteContent(url)

block:
  let url: Uri = parseUri("https://httpbin.org/post")
  let content: cstring = client.postContent(url, data)

block:
  let url: Uri = parseUri("https://httpbin.org/put")
  let content: cstring = client.putContent(url, data)

block:
  let url: Uri = parseUri("https://httpbin.org/patch")
  let content: cstring = client.patchContent(url, data)

Procs

func deleteContent(self: JsHttpClient; url: Uri | string): cstring
func getContent(self: JsHttpClient; url: Uri | string): cstring
func head(self: JsHttpClient; url: Uri | string): cstring
func newJsHttpClient(): JsHttpClient {.importjs: "new XMLHttpRequest()",
                                       ...raises: [], tags: [].}
func patchContent(self: JsHttpClient; url: Uri | string; body: cstring = ""): cstring
func postContent(self: JsHttpClient; url: Uri | string; body: cstring = ""): cstring
func putContent(self: JsHttpClient; url: Uri | string; body: cstring = ""): cstring