Skip to main content

Post

Sends a POST request to the supplied URL.

Parameters

Parameter NameParameter TypeParameter Description
urlstringThe URL to send the POST request to
datastringThe Data to send to the URL
mediaTypeHttpMediaTypeThe MediaType of the data provided

The following example gets a User from an example Hypernex API Server (assuming localhost), parses the json (see JSON (Lua)/JSON (JavaScript)), then prints the Username.

JavaScript

let http = new Http()
let data = "{\"userid\": \"user_77c834ec-e673-449c-a652-68da917187ff\"}"
let result = http.Post("http://localhost/api/v1/getUser", data, HttpMediaType.ApplicationJSON)
let j = JSON.parse(result)
print(j["Username"])

Lua

local http = Http()
local data = "{\"userid\": \"user_77c834ec-e673-449c-a652-68da917187ff\"}"
local result = http.Post("http://localhost/api/v1/getUser", data, HttpMediaType.ApplicationJSON)
local j = json.parse(result)
print(result["Username"])