pkulchenko / fullmoon

Fast and minimalistic Redbean-based Lua web framework in one file.
MIT License
684 stars 30 forks source link

How to call other domain from inside fullmoon? #37

Closed kuslahne closed 6 months ago

kuslahne commented 6 months ago

Thank you for your great framework. Is there an example for accessing other url from fullmoon let say I need to fetch json data from https://jsonplaceholder.typicode.com/todos/1 and prosess their response? Is this possible without using ajax in js file? Or we can use external lua package? There is no documentation for HTTP client access here.

Thank you

pkulchenko commented 6 months ago

Yes, you should definitely be able to do that. Redbean provides Fetch function (available as fm.fetch from fullmoon) that allows submitting http/https requests and processing of responses (including redirects).

This would be the simplest call: assert(fm.fetch("https://imgs.xkcd.com/comics/star_ratings.png")).

I'll update the documentation to mention that and include some examples. Feel free to re-open if you have other questions.