I'd like to call an API that is "out there" so I can display live data on my Love2D screen. Think of a stock ticker or live hockey score updates. Here is an example:
https://rapidapi.com/asepscareer/api/yahoo-finance97
How would I invoke something like that in Love/LUA? Is POST within the realms of possibility? Would I need FFI? How do I get started on something like this? Thanks.
How to call web services/API?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to call web services/API?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: How to call web services/API?
Love2d provides luasocket out of the box, and you can use it to implement some simple POST requests. From the reference, the request page has relevant details, and there are fair few luasocket tutorials out there. The main catch is that it may be wise to run the networking requests on a separate thread (in case of a blocking operation), so not to block the main thread execution.
Re: How to call web services/API?
I think the main catch is actually that https is not supported.
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: How to call web services/API?
Right, I forgot about https specifically. Of course, that depends on if you can just roll with http or not.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to call web services/API?
yet*
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: How to call web services/API?
So it seems all currency exchange API's use https. Is that not gunna work with Love2D? Are there https libraries I should google for? Should I mess about with this: https://github.com/love2d/lua-https
Or this: https://github.com/daurnimator/lua-http (supports https 1.2)
I'll keep googling for a http but all the sites I've seen have an identical look and feel (same company - same API - same https) but just researching this alone is educational.
Edit: this site offers http: http://api.nbp.pl/en.html
and by typing into a browser: http://api.nbp.pl/api/exchangerates/tables/a/
I get the following xml:
I think this is enough for me to play and learn.
Or this: https://github.com/daurnimator/lua-http (supports https 1.2)
I'll keep googling for a http but all the sites I've seen have an identical look and feel (same company - same API - same https) but just researching this alone is educational.
Edit: this site offers http: http://api.nbp.pl/en.html
and by typing into a browser: http://api.nbp.pl/api/exchangerates/tables/a/
I get the following xml:
Code: Select all
<ArrayOfExchangeRatesTable>
<ExchangeRatesTable>
<Table>A</Table>
<No>195/A/NBP/2022</No>
<EffectiveDate>2022-10-07</EffectiveDate>
<Rates>
<Rate>
<Currency>bat (Tajlandia)</Currency>
<Code>THB</Code>
<Mid>0.1326</Mid>
</Rate>
<Rate>
<Currency>dolar amerykański</Currency>
<Code>USD</Code>
<Mid>4.9588</Mid>
</Rate>
...
...
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
Re: How to call web services/API?
You could use CURL binding https://github.com/Lua-cURL/Lua-cURLv3 insteadtogFox wrote: ↑Fri Oct 07, 2022 12:55 pm So it seems all currency exchange API's use https. Is that not gunna work with Love2D? Are there https libraries I should google for? Should I mess about with this: https://github.com/love2d/lua-https
Or this: https://github.com/daurnimator/lua-http (supports https 1.2)
I'll keep googling for a http but all the sites I've seen have an identical look and feel (same company - same API - same https) but just researching this alone is educational.
[snip...]
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Who is online
Users browsing this forum: No registered users and 5 guests