56 rader
1.3 KiB

  1. //
  2. // Lol Engine — HTTP client sample
  3. //
  4. // Copyright © 2016—2020 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #if HAVE_CONFIG_H
  13. # include "config.h"
  14. #endif
  15. #include <lol/engine.h>
  16. class demo : public lol::entity
  17. {
  18. public:
  19. virtual bool init_game() override
  20. {
  21. // Choose URL that works with CORS (cross-origin resource sharing)
  22. client.get("https://api.github.com/");
  23. return true;
  24. }
  25. virtual void tick_game(float seconds) override
  26. {
  27. entity::tick_game(seconds);
  28. if (client.get_status() == lol::net::http::status::success)
  29. {
  30. lol::msg::info("Downloaded %d bytes: %s\n",
  31. (int)client.get_result().size(),
  32. client.get_result().c_str());
  33. client.reset();
  34. }
  35. }
  36. lol::net::http::client client;
  37. };
  38. int main(int argc, char **argv)
  39. {
  40. lol::sys::init(argc, argv);
  41. lol::Application app("Tutorial 17: HTTP", lol::ivec2(800, 600), 60.0f);
  42. auto p = new demo();
  43. app.Run();
  44. return 0;
  45. }