quick_rest: starting with building request
parent
7d28760614
commit
ae36b37036
|
|
@ -0,0 +1,17 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="run rq" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="just build-qr run-qr" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/zsh" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="true" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="false" />
|
||||||
|
<envs />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
print "Start quick_rest script"
|
print "Start quick_rest script"
|
||||||
local qr = require "quick_rest"
|
local qr = require "quick_rest"
|
||||||
|
|
||||||
print(qr)
|
|
||||||
|
|
||||||
--local http_client = qr.http_client {
|
--local http_client = qr.http_client {
|
||||||
-- concurreny_limit = 10
|
-- 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 {
|
-- .json {
|
||||||
-- username = "klara@bpa.de",
|
-- username = "klara@bpa.de",
|
||||||
-- password = "abcdedf"
|
-- password = "abcdedf"
|
||||||
-- }
|
-- }
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
--print(request)
|
print(request)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,32 @@
|
||||||
use crate::http_request_body::HttpRequestBody;
|
use crate::http_request_body::HttpRequestBody;
|
||||||
|
use reqwest::Url;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[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, "<HttpRequest> {} {}", 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 {
|
impl HttpRequest {
|
||||||
pub fn get() -> HttpRequest {
|
pub fn get() -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
@ -9,8 +34,11 @@ impl HttpRequest {
|
||||||
pub fn put() -> HttpRequest {
|
pub fn put() -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
pub fn post() -> HttpRequest {
|
pub fn post(url: Url) -> HttpRequest {
|
||||||
todo!()
|
HttpRequest {
|
||||||
|
method: HttpMethod::POST,
|
||||||
|
url,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn patch() -> HttpRequest {
|
pub fn patch() -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,3 @@ mod http_service_builder;
|
||||||
mod http_service_wrapper;
|
mod http_service_wrapper;
|
||||||
mod lua_bindings;
|
mod lua_bindings;
|
||||||
mod network_error;
|
mod network_error;
|
||||||
#[mlua::lua_module]
|
|
||||||
fn quick_rest(lua: &Lua) -> LuaResult<LuaTable> {
|
|
||||||
let exports = lua.create_table()?;
|
|
||||||
Ok(exports)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,20 @@
|
||||||
|
mod lua_http_request;
|
||||||
|
|
||||||
|
use crate::http_request::HttpRequest;
|
||||||
use mlua::prelude::{LuaResult, LuaTable};
|
use mlua::prelude::{LuaResult, LuaTable};
|
||||||
use mlua::Lua;
|
use mlua::Lua;
|
||||||
|
use reqwest::Url;
|
||||||
|
|
||||||
|
fn post(lua: &Lua, url: String) -> LuaResult<HttpRequest> {
|
||||||
|
let url: Url = url.parse().expect("invalid url");
|
||||||
|
Ok(HttpRequest::post(url))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[mlua::lua_module]
|
||||||
|
fn quick_rest(lua: &Lua) -> LuaResult<LuaTable> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue