build quick_rest module
parent
b2605aa620
commit
7d28760614
|
|
@ -3662,6 +3662,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures",
|
"futures",
|
||||||
|
"mlua",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tower",
|
"tower",
|
||||||
|
|
|
||||||
4
justfile
4
justfile
|
|
@ -9,6 +9,10 @@ run-rr: (lua "rr.example.lua")
|
||||||
build-rr: (_copy-so "dev" "rerun_lua")
|
build-rr: (_copy-so "dev" "rerun_lua")
|
||||||
deploy-rr: (_deploy "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 file:
|
||||||
LUA_CPATH=c_modules/?.so lua lua/{{file}}
|
LUA_CPATH=c_modules/?.so lua lua/{{file}}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -3,11 +3,13 @@ name = "quick_rest"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = { version = "0.11.22", features = ["stream", "json"] }
|
reqwest = { version = "0.11.22", features = ["stream", "json"] }
|
||||||
bytes = "1.5.0"
|
bytes = "1.5.0"
|
||||||
tower = { version = "0.4.13", features = ["full"] }
|
tower = { version = "0.4.13", features = ["full"] }
|
||||||
thiserror = "1.0.50"
|
thiserror = "1.0.50"
|
||||||
futures = "0.3.29"
|
futures = "0.3.29"
|
||||||
|
mlua = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use bytes::Bytes;
|
use crate::http_request_body::HttpRequestBody;
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct HttpRequest {}
|
pub struct HttpRequest {}
|
||||||
impl HttpRequest {
|
impl HttpRequest {
|
||||||
pub fn get() -> HttpRequest {
|
pub fn get() -> HttpRequest {
|
||||||
|
|
@ -9,14 +9,12 @@ impl HttpRequest {
|
||||||
pub fn put() -> HttpRequest {
|
pub fn put() -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post() -> HttpRequest {
|
pub fn post() -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
pub fn patch() -> HttpRequest {
|
pub fn patch() -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn head() -> HttpRequest {
|
pub fn head() -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
@ -35,5 +33,11 @@ impl HttpRequest {
|
||||||
pub fn add_header(&self, key: String, value: String) -> HttpRequest {
|
pub fn add_header(&self, key: String, value: String) -> HttpRequest {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
pub fn into_reqwest(&self) -> reqwest::Request {}
|
|
||||||
|
pub fn body(&self, body: HttpRequestBody) -> HttpRequest {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn into_reqwest(&self) -> reqwest::Request {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,7 @@
|
||||||
pub struct HttpRequestBody {}
|
pub struct HttpRequestBody {}
|
||||||
|
|
||||||
|
impl HttpRequestBody {
|
||||||
|
pub fn from_string(content: String) -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
pub struct HttpResponse {}
|
pub struct HttpResponse {}
|
||||||
|
|
||||||
|
unsafe impl Send for HttpResponse {}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ use crate::http_response::HttpResponse;
|
||||||
use crate::network_error::NetworkError;
|
use crate::network_error::NetworkError;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
use tower::timeout::future::ResponseFuture;
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
|
||||||
pub struct HttpService {
|
pub struct HttpService {
|
||||||
|
|
@ -20,7 +22,7 @@ impl Default for HttpService {
|
||||||
impl Service<HttpRequest> for HttpService {
|
impl Service<HttpRequest> for HttpService {
|
||||||
type Response = HttpResponse;
|
type Response = HttpResponse;
|
||||||
type Error = NetworkError;
|
type Error = NetworkError;
|
||||||
type Future = Box<dyn Future<Output = Result<Self::Response, Self::Error>>>;
|
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
|
use mlua::prelude::{LuaResult, LuaTable, LuaThread};
|
||||||
|
use mlua::Lua;
|
||||||
|
|
||||||
mod http_request;
|
mod http_request;
|
||||||
mod http_request_body;
|
mod http_request_body;
|
||||||
mod http_response;
|
mod http_response;
|
||||||
mod http_service;
|
mod http_service;
|
||||||
mod http_service_builder;
|
mod http_service_builder;
|
||||||
mod http_service_wrapper;
|
mod http_service_wrapper;
|
||||||
|
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,2 @@
|
||||||
|
use mlua::prelude::{LuaResult, LuaTable};
|
||||||
|
use mlua::Lua;
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
|
use crate::http_response::HttpResponse;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error)]
|
#[derive(Error, Debug)]
|
||||||
|
#[error("Ups :( Networkerror")]
|
||||||
pub struct NetworkError {}
|
pub struct NetworkError {}
|
||||||
|
unsafe impl Send for NetworkError {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue