From 14c02cf10cecbc8457bf93bf251f35b5f1fcf2c2 Mon Sep 17 00:00:00 2001 From: punkers01 Date: Fri, 21 Jun 2024 12:20:22 +0100 Subject: [PATCH 1/2] Update README.md with a more complex POST request --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 59c02f5a..446f313b 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,29 @@ local status = res.status local length = res.headers["Content-Length"] local body = res.body ``` +Example #2 +```lua +local cjson = require "cjson" +local httpc = require("resty.http").new() +local payload = { + Source="abc1", + contactId="id145" +} +local resp, resp_err = httpc:request_uri("http://example.com/helloworld", { + method = "POST", + headers = { + ["accept"] = "application/json", + ["Content-Type"] = "application/json", + ["Authentication"] = "Bearer " .. your_token + }, + body = cjson.encode(get_contact_payload) --convert to json from lua table + }) +if resp_err then + print("error: ", resp_err) +else + print("body ", resp.body) + local data = cjson.decode(resp.body) -- convert into a lua table +end ### Streamed request From 3e0716c69f20f293798605824cd6fec06f64c84c Mon Sep 17 00:00:00 2001 From: punkers01 Date: Fri, 21 Jun 2024 12:26:29 +0100 Subject: [PATCH 2/2] Update README.md added closing ``` --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 446f313b..5c15b11c 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ else print("body ", resp.body) local data = cjson.decode(resp.body) -- convert into a lua table end +``` ### Streamed request