https://github.com/jgramoll/kong-rust-pdk
Plugin Development Kit (PDK) in Rust. Supports writing custom plugins for Kong (https://github.com/Kong/kong)
https://github.com/jgramoll/kong-rust-pdk
kong pdk prost protobuf rust-lang tokio-rs
Last synced: 7 days ago
JSON representation
Plugin Development Kit (PDK) in Rust. Supports writing custom plugins for Kong (https://github.com/Kong/kong)
- Host: GitHub
- URL: https://github.com/jgramoll/kong-rust-pdk
- Owner: jgramoll
- Created: 2021-09-20T06:07:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-06T21:17:48.000Z (over 3 years ago)
- Last Synced: 2025-03-31T00:24:51.596Z (about 1 month ago)
- Topics: kong, pdk, prost, protobuf, rust-lang, tokio-rs
- Language: Rust
- Homepage:
- Size: 122 KB
- Stars: 18
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kong Rust PDK
## Example
```toml
# Cargo.toml
[dependencies]
kong-rust-pdk = { git = "https://github.com/jgramoll/kong-rust-pdk" }
serde = "1.0"
tokio = { version = "1.11", features = ["macros", "rt-multi-thread"] }
``````rs
// src/main.rs
use kong_rust_pdk::{macros::*, pdk::Pdk, server, Error, Plugin};const VERSION: &str = "0.1";
const PRIORITY: usize = 1;#[tokio::main]
async fn main() -> Result<(), Box> {
server::start::(VERSION, PRIORITY).await?;Ok(())
}#[plugin_config]
struct Config {
message: String,
}impl Default for Config {
fn default() -> Self {
Self {
message: String::from("default message"),
}
}
}#[plugin_impl]
impl Plugin for Config {
async fn access(&self, kong: &mut T) -> Result<(), Error> {
let method = kong.request().get_method().await?;kong.response().set_status(204).await?;
kong.response()
.set_header("x-hello-from-rust", &method)
.await?;Ok(())
}
}
```## Modules
* kong-rust-pdk-macro - macros for use in pdk implementation
* kong-rust-pdk-proto - convert .proto file to rust objects
* kong-rust-pdk - core logic for pluginserver
* serde-prost-types - wrapper for prost-types to support serde annotations## Local dev
Start plugin server
```
RUST_LOG=info cargo run --bin helloworld
```Send command from kong to run plugin
```
cargo run --bin kong_mock
```debug macro
```
cargo expand --bin helloworld
```