Protect one Route of Service

Hello, I would like to protect one route of my Service with a api key.

My Service has Endpoints like GET /posts POST /posts and so on. I Would only like to protect POST /posts. Is this possible? What is best practice to structure my service in kong?

Hello @volbrene

I tested with httpbin.org for example service

First, add service, Then add 2 routes

  1. GET-anything
  • paths : /anything
  • methods: GET
  1. POST-anything
  • paths : /anything
  • methods: POST

Now you have 2 routes for GET, POST at the same endpoint

Then you can enable the plugin per route


Kong service/routes

{
  "next": null,
  "data": [
    {
      "id": "14e4ee6e-a27c-4617-9842-37fb72f6010c",
      "tags": null,
      "updated_at": 1574046258,
      "destinations": null,
      "headers": null,
      "protocols": [
        "http",
        "https"
      ],
      "created_at": 1574046258,
      "snis": null,
      "service": {
        "id": "ec5a9133-1234-4366-84a1-081d6db793d9"
      },
      "name": "GET-anything",
      "preserve_host": false,
      "regex_priority": 0,
      "strip_path": false,
      "sources": null,
      "paths": [
        "/anything"
      ],
      "https_redirect_status_code": 426,
      "hosts": null,
      "methods": [
        "GET"
      ]
    },
    {
      "id": "f805fe41-d4a7-4f69-b9a6-d6624cee8c89",
      "tags": null,
      "updated_at": 1574046295,
      "destinations": null,
      "headers": null,
      "protocols": [
        "http",
        "https"
      ],
      "created_at": 1574046295,
      "snis": null,
      "service": {
        "id": "ec5a9133-1234-4366-84a1-081d6db793d9"
      },
      "name": "POST-anything",
      "preserve_host": false,
      "regex_priority": 0,
      "strip_path": false,
      "sources": null,
      "paths": [
        "/anything"
      ],
      "https_redirect_status_code": 426,
      "hosts": null,
      "methods": [
        "POST"
      ]
    }
  ]
}