This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mudgw2's profile picture

Basic HTTP API (JSON) example?

Started by mudgw2, 13 August 2014 - 03:14 PM
mudgw2 #1
Posted 13 August 2014 - 05:14 PM
Greetings!

I'm a web developer whos got background in php and I'm really interested in some of the API/JSON stuff I see with CC. However, my java knowledge is limited and my lua is as well.

What I would like to do is use CC to monitor energy (which I have done in-game using CC Computers), but have the data go to my webserver? I'd then like to capture that JSON and display it on a webpage.

I've seen examples of this but there is very little information on how this process works at its core, mostly just working examples and I also don't want to send data to a foreign host.

Any suggestions on where to start?

Thanks!
MKlegoman357 #2
Posted 13 August 2014 - 08:32 PM
You would use the HTTP API for that. It allows you to make either GET or POST requests with which you could send your desired data to your webserver. Note that if someone would find out about your website and/or get the source code of the program you are uploading with could spam your website with incorrect data, be aware on MC servers!
Edited on 13 August 2014 - 06:33 PM
mudgw2 #3
Posted 13 August 2014 - 09:17 PM
Thanks, I'm already aware of that and I'm running on a private server so security isn't a concern. I'm still looking for some example code someplace that shows that if I enter in this lua on CC it will produce json to a URL. Where I can at the destination read that json and save it to mysql. But I dont find any clear examples of that.

If anyone has direction I'd appreciate it.
Cranium #4
Posted 13 August 2014 - 09:50 PM
Simply put, you can pas any string as a POST request to your URL of choice. It's up to whatever you have written in the webserver as to what to do with the string.
Take a look at the built in pastebin program, as it uses the POST request to get all of its information to and from pastebin.
mudgw2 #5
Posted 13 August 2014 - 09:57 PM
Ah ok, didn't think to check that..thanks!