diff --git a/.run/run rq.run.xml b/.run/run rq.run.xml
new file mode 100644
index 0000000..8eb1ee1
--- /dev/null
+++ b/.run/run rq.run.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lua/qr.example.lua b/lua/qr.example.lua
index b9d4550..201f0a3 100644
--- a/lua/qr.example.lua
+++ b/lua/qr.example.lua
@@ -1,17 +1,16 @@
print "Start quick_rest script"
local qr = require "quick_rest"
-print(qr)
--local http_client = qr.http_client {
-- concurreny_limit = 10
--}
---local request = qr.request.post("https://api.internal.insiders.cloud/1/rest/accounts/authentication/requesttoken")
+local request = qr.request.post("https://api.internal.insiders.cloud/1/rest/accounts/authentication/requesttoken")
-- .json {
-- username = "klara@bpa.de",
-- password = "abcdedf"
-- }
--
--
---print(request)
+print(request)
diff --git a/lua_modules/quick_rest/src/http_request.rs b/lua_modules/quick_rest/src/http_request.rs
index bbe6509..302fe45 100644
--- a/lua_modules/quick_rest/src/http_request.rs
+++ b/lua_modules/quick_rest/src/http_request.rs
@@ -1,7 +1,32 @@
use crate::http_request_body::HttpRequestBody;
+use reqwest::Url;
+use std::fmt::{Display, Formatter};
#[derive(Clone)]
-pub struct HttpRequest {}
+pub struct HttpRequest {
+ method: HttpMethod,
+ url: Url,
+}
+
+#[derive(Clone)]
+pub enum HttpMethod {
+ POST,
+}
+
+impl Display for HttpRequest {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ write!(f, " {} {}", self.method, self.url)
+ }
+}
+
+impl Display for HttpMethod {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ let name = match (self) {
+ HttpMethod::POST => "POST",
+ };
+ write!(f, "{name}")
+ }
+}
impl HttpRequest {
pub fn get() -> HttpRequest {
todo!()
@@ -9,8 +34,11 @@ impl HttpRequest {
pub fn put() -> HttpRequest {
todo!()
}
- pub fn post() -> HttpRequest {
- todo!()
+ pub fn post(url: Url) -> HttpRequest {
+ HttpRequest {
+ method: HttpMethod::POST,
+ url,
+ }
}
pub fn patch() -> HttpRequest {
todo!()
diff --git a/lua_modules/quick_rest/src/lib.rs b/lua_modules/quick_rest/src/lib.rs
index 462817e..b15eca2 100644
--- a/lua_modules/quick_rest/src/lib.rs
+++ b/lua_modules/quick_rest/src/lib.rs
@@ -9,8 +9,3 @@ mod http_service_builder;
mod http_service_wrapper;
mod lua_bindings;
mod network_error;
-#[mlua::lua_module]
-fn quick_rest(lua: &Lua) -> LuaResult {
- let exports = lua.create_table()?;
- Ok(exports)
-}
diff --git a/lua_modules/quick_rest/src/lua_bindings/lua_http_request.rs b/lua_modules/quick_rest/src/lua_bindings/lua_http_request.rs
new file mode 100644
index 0000000..366c9d0
--- /dev/null
+++ b/lua_modules/quick_rest/src/lua_bindings/lua_http_request.rs
@@ -0,0 +1,10 @@
+use crate::http_request::HttpRequest;
+use mlua::{MetaMethod, UserData, UserDataMethods};
+
+impl UserData for HttpRequest {
+ fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
+ methods.add_meta_method(MetaMethod::ToString, |_, http_request, _: ()| {
+ Ok(http_request.to_string())
+ })
+ }
+}
diff --git a/lua_modules/quick_rest/src/lua_bindings/mod.rs b/lua_modules/quick_rest/src/lua_bindings/mod.rs
index 8bfb606..a44620e 100644
--- a/lua_modules/quick_rest/src/lua_bindings/mod.rs
+++ b/lua_modules/quick_rest/src/lua_bindings/mod.rs
@@ -1,2 +1,20 @@
+mod lua_http_request;
+
+use crate::http_request::HttpRequest;
use mlua::prelude::{LuaResult, LuaTable};
use mlua::Lua;
+use reqwest::Url;
+
+fn post(lua: &Lua, url: String) -> LuaResult {
+ let url: Url = url.parse().expect("invalid url");
+ Ok(HttpRequest::post(url))
+}
+
+#[mlua::lua_module]
+fn quick_rest(lua: &Lua) -> LuaResult {
+ let exports = lua.create_table()?;
+ let request_table = lua.create_table()?;
+ request_table.set("post", lua.create_function(post)?)?;
+ exports.set("request", request_table)?;
+ Ok(exports)
+}