QA
Senior LevelREST APIs & Web Services

How do you write a custom High-Performance Lua Plugin for Kong API Gateway?

❓ Interview Prompt: Explain Kong API Gateway plugin architecture, OpenResty / NGINX Lua execution phase hooks (`access`, `header_filter`), and high-performance request transformation.

Extending Kong API Gateway capabilities using custom Lua plugins running on the OpenResty / NGINX event loop:

OpenResty Execution Phases:

•
'access()': Executed for every request before forwarding to upstream microservices. Ideal for custom HMAC validation or token transformation.
•
'header_filter()': Executed when receiving response headers from upstream. Ideal for stripping internal server headers.
•
Operates asynchronously with sub-millisecond overhead!

Code Implementation Example

lua
-- Kong Custom Access Plugin (custom_auth/handler.lua)
local CustomHandler = { PRIORITY = 1000, VERSION = "1.0.0" }

function CustomHandler:access(conf)
  local token = kong.request.get_header("X-Custom-Auth")
  if not token or token ~= conf.secret_token then
    return kong.response.exit(401, { message = "Invalid Custom Authorization Header" })
  end
end

return CustomHandler
💡Custom Kong API Gateway Lua plugin executing in access phase.
🎯 Interview Key Takeaway

Write custom Kong plugins in Lua running on OpenResty execution phases to execute custom security checks with sub-millisecond latency.

#Kong#Lua#API Gateway#OpenResty#Senior
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?