Skip to content

Commit

Permalink
Transfer HTTP client examples to lua_examples/
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstoer committed Jan 24, 2016
1 parent 2e16e3a commit a502c1b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lua_examples/http-client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- Support HTTP and HTTPS, For example
-- HTTP POST Example with JSON header and body
http.post("http://somewhere.acceptjson.com/",
"Content-Type: application/json\r\n",
"{\"hello\":\"world\"}",
function(code, data)
print(code)
print(data)
end)

-- HTTPS GET Example with NULL header
http.get("https://www.vowstar.com/nodemcu/","",
function(code, data)
print(code)
print(data)
end)
-- You will get
-- > 200
-- hello nodemcu

-- HTTPS DELETE Example with NULL header and body
http.delete("https://10.0.0.2:443","","",
function(code, data)
print(code)
print(data)
end)

-- HTTPS PUT Example with NULL header and body
http.put("https://testput.somewhere/somewhereyouput.php","","",
function(code, data)
print(code)
print(data)
end)

-- HTTP RAW Request Example, use more HTTP/HTTPS request method
http.request("http://www.apple.com:80/library/test/success.html","GET","","",
function(code, data)
print(code)
print(data)
end)

This comment has been minimized.

Copy link
@devsaurus

devsaurus Jan 25, 2016

Missing newline at end of file? 😉

This comment has been minimized.

Copy link
@marcelstoer

marcelstoer Jan 25, 2016

Author Owner

True, GitHub says so...is that required? Other example scripts don't have that either.

2 comments on commit a502c1b

@devsaurus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that required?

Probably not. I guess that editors, loaders and the embedded Lua readline will handle it properly. But if you start to concatenate files it can be a pain.

@marcelstoer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll amend the commit and add one anyway. Found out that the C language standard mandates this but couldn't find anything for Lua.

Please sign in to comment.