diff --git a/Cargo.lock b/Cargo.lock index ecda98b..912b61c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3662,6 +3662,7 @@ version = "0.1.0" dependencies = [ "bytes", "futures", + "mlua", "reqwest", "thiserror", "tower", diff --git a/justfile b/justfile index 80f6398..759981f 100755 --- a/justfile +++ b/justfile @@ -9,6 +9,10 @@ run-rr: (lua "rr.example.lua") build-rr: (_copy-so "dev" "rerun_lua") deploy-rr: (_deploy "rerun_lua") +run-qr: (lua "qr.example.lua") +build-qr: (_copy-so "dev" "quick_rest") +deploy-qr: (_deploy "quick_rest") + lua file: LUA_CPATH=c_modules/?.so lua lua/{{file}} diff --git a/lua/qr.example.lua b/lua/qr.example.lua new file mode 100644 index 0000000..b9d4550 --- /dev/null +++ b/lua/qr.example.lua @@ -0,0 +1,17 @@ +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") +-- .json { +-- username = "klara@bpa.de", +-- password = "abcdedf" +-- } +-- +-- +--print(request) diff --git a/lua_modules/quick_rest/Cargo.toml b/lua_modules/quick_rest/Cargo.toml index ced883d..1159490 100644 --- a/lua_modules/quick_rest/Cargo.toml +++ b/lua_modules/quick_rest/Cargo.toml @@ -3,11 +3,13 @@ name = "quick_rest" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["cdylib"] [dependencies] reqwest = { version = "0.11.22", features = ["stream", "json"] } bytes = "1.5.0" tower = { version = "0.4.13", features = ["full"] } thiserror = "1.0.50" -futures = "0.3.29" \ No newline at end of file +futures = "0.3.29" +mlua = { workspace = true } diff --git a/lua_modules/quick_rest/src/http_request.rs b/lua_modules/quick_rest/src/http_request.rs index 639892e..bbe6509 100644 --- a/lua_modules/quick_rest/src/http_request.rs +++ b/lua_modules/quick_rest/src/http_request.rs @@ -1,6 +1,6 @@ -use bytes::Bytes; -use std::path::PathBuf; +use crate::http_request_body::HttpRequestBody; +#[derive(Clone)] pub struct HttpRequest {} impl HttpRequest { pub fn get() -> HttpRequest { @@ -9,14 +9,12 @@ impl HttpRequest { pub fn put() -> HttpRequest { todo!() } - pub fn post() -> HttpRequest { todo!() } pub fn patch() -> HttpRequest { todo!() } - pub fn head() -> HttpRequest { todo!() } @@ -35,5 +33,11 @@ impl HttpRequest { pub fn add_header(&self, key: String, value: String) -> HttpRequest { todo!() } - pub fn into_reqwest(&self) -> reqwest::Request {} + + pub fn body(&self, body: HttpRequestBody) -> HttpRequest { + todo!() + } + pub fn into_reqwest(&self) -> reqwest::Request { + todo!() + } } diff --git a/lua_modules/quick_rest/src/http_request_body.rs b/lua_modules/quick_rest/src/http_request_body.rs index b21c9fe..5918121 100644 --- a/lua_modules/quick_rest/src/http_request_body.rs +++ b/lua_modules/quick_rest/src/http_request_body.rs @@ -1 +1,7 @@ pub struct HttpRequestBody {} + +impl HttpRequestBody { + pub fn from_string(content: String) -> Self { + todo!() + } +} diff --git a/lua_modules/quick_rest/src/http_response.rs b/lua_modules/quick_rest/src/http_response.rs index 1e9eb7c..8fd4e6a 100644 --- a/lua_modules/quick_rest/src/http_response.rs +++ b/lua_modules/quick_rest/src/http_response.rs @@ -1 +1,3 @@ pub struct HttpResponse {} + +unsafe impl Send for HttpResponse {} diff --git a/lua_modules/quick_rest/src/http_service.rs b/lua_modules/quick_rest/src/http_service.rs index 759be2b..f561b3b 100644 --- a/lua_modules/quick_rest/src/http_service.rs +++ b/lua_modules/quick_rest/src/http_service.rs @@ -3,7 +3,9 @@ use crate::http_response::HttpResponse; use crate::network_error::NetworkError; use reqwest::Client; use std::future::Future; +use std::pin::Pin; use std::task::{Context, Poll}; +use tower::timeout::future::ResponseFuture; use tower::Service; pub struct HttpService { @@ -20,7 +22,7 @@ impl Default for HttpService { impl Service for HttpService { type Response = HttpResponse; type Error = NetworkError; - type Future = Box>>; + type Future = Pin> + Send>>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { todo!() diff --git a/lua_modules/quick_rest/src/lib.rs b/lua_modules/quick_rest/src/lib.rs index 4d3848f..462817e 100644 --- a/lua_modules/quick_rest/src/lib.rs +++ b/lua_modules/quick_rest/src/lib.rs @@ -1,7 +1,16 @@ +use mlua::prelude::{LuaResult, LuaTable, LuaThread}; +use mlua::Lua; + mod http_request; mod http_request_body; mod http_response; mod http_service; 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/mod.rs b/lua_modules/quick_rest/src/lua_bindings/mod.rs new file mode 100644 index 0000000..8bfb606 --- /dev/null +++ b/lua_modules/quick_rest/src/lua_bindings/mod.rs @@ -0,0 +1,2 @@ +use mlua::prelude::{LuaResult, LuaTable}; +use mlua::Lua; diff --git a/lua_modules/quick_rest/src/network_error.rs b/lua_modules/quick_rest/src/network_error.rs index 4840dab..631d6b7 100644 --- a/lua_modules/quick_rest/src/network_error.rs +++ b/lua_modules/quick_rest/src/network_error.rs @@ -1,4 +1,7 @@ +use crate::http_response::HttpResponse; use thiserror::Error; -#[derive(Error)] +#[derive(Error, Debug)] +#[error("Ups :( Networkerror")] pub struct NetworkError {} +unsafe impl Send for NetworkError {}