An open API service indexing awesome lists of open source software.

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)

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
```