build quick_rest module
parent
b2605aa620
commit
7d28760614
|
|
@ -3662,6 +3662,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bytes",
|
||||
"futures",
|
||||
"mlua",
|
||||
"reqwest",
|
||||
"thiserror",
|
||||
"tower",
|
||||
|
|
|
|||
4
justfile
4
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}}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,7 +3,8 @@ 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"] }
|
||||
|
|
@ -11,3 +12,4 @@ bytes = "1.5.0"
|
|||
tower = { version = "0.4.13", features = ["full"] }
|
||||
thiserror = "1.0.50"
|
||||
futures = "0.3.29"
|
||||
mlua = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -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!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
pub struct HttpRequestBody {}
|
||||
|
||||
impl HttpRequestBody {
|
||||
pub fn from_string(content: String) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
pub struct HttpResponse {}
|
||||
|
||||
unsafe impl Send for HttpResponse {}
|
||||
|
|
|
|||
|
|
@ -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<HttpRequest> for HttpService {
|
||||
type Response = HttpResponse;
|
||||
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>> {
|
||||
todo!()
|
||||
|
|
|
|||
|
|
@ -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<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;
|
||||
|
||||
#[derive(Error)]
|
||||
#[derive(Error, Debug)]
|
||||
#[error("Ups :( Networkerror")]
|
||||
pub struct NetworkError {}
|
||||
unsafe impl Send for NetworkError {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue