All I want is to access a RESTful API - specifically https://pokeapi.co/ - so for example, if you visit https://pokeapi.co/api/v2/pokemon/ditto and see a bunch of raw JSON, that's what I'm trying to access within Love2d and eventually convert it into a Lua table.
So I made my way over to https://love2d.org/wiki/Networking and checked out the available options for networking. "socket" seems to be the most simple and well supported. However, when using "socket," I've come to realize it cannot support HTTPS. I only get 301 errors, and through my research it seems that's a result of an attempted https:// to http:// redirect or vice versa, I may have the details backward.
I've tried changing the URL manually from https:// to http:// with no effect. I've tried appending a slash to the URL which has worked for some people in similar situations across the internet but it also had no effect, simply returning a 301 error through "socket."
It seems to be the lack of HTTPS support with "socket" that is the actual problem, so I've checked out the other networking options. "lua-https" seems to be what I need, and I've spent the past few hours trying to figure out how to use CMAKE to compile it from the source since LOVE 12 isn't released yet... but I could really use some guidance on how to implement "lua-https," I find the whole process very confusing. CMAKE seems to think the project files included within the "lua-https" source are corrupt or somehow incorrect? I'm positive it's just USER ERROR, but I don't really know where to look for the level of support my feeble brain can actually understand.
Is there a reference for a step-by-step installation of a Lua module into Love2d, building from source? Is there something about the HTTPS module that is commonly misunderstood? Am I just too dumb to continue programming? Haha.
I'm happy to provide source, although I don't really know how it would help, here's what I tried with "socket", and I was unable to ever get the "lua-https" module built so I didn't get to make any attempts with that.
Code: Select all
local http = require("socket.http")
function love.load()
testUrl = "http://pokeapi.co/api/v2/pokemon/?limit=151"
restTest, restTwo = http.request(testUrl)
end
function love.draw()
love.graphics.print(restTest .. "\n" .. restTwo)
end
"http://pokeapi.co/api/v2/pokemon?limit=151" (no trailing slash)
"http://pokeapi.co/api/v2/pokemon/?limit=151" (trailing slash)
"https://pokeapi.co/api/v2/pokemon?limit=151" (https)
"https://pokeapi.co/api/v2/pokemon/?limit=151" (https w/ trailing slash)
All of these addresses work when typed into a web browser.
Any advice would be appreciated, I think I know what I need to do to implement "lua-https" in concept, but in practice I feel like I'm hitting a brick wall learning how to compile with CMAKE and all that. I should also mention that the end goal of this project is to be able to play this game on mobile... and I feel like if I'm needing to compile from source and developing on Windows that I'll have to redo it when it comes time to actually release on Android so I should figure out how to actually do it myself rather than just have somebody pass me a precompiled binary. But perhaps I'm really missing the mark altogether.
Hep meh? <3