Create and consume new service/route in lasted version (0.13.0))

Hi, I have problems registering a new service and asociated routes in the lasted version and I hope you can help me.

For this example i want registed the apis resources published in:
https://jsonplaceholder.typicode.com
/posts
/posts/:id

So i registed the service that:

  {
        "host": "jsonplaceholder.typicode.com",
        "created_at": 1522978184,
        "connect_timeout": 60000,
        "id": "9cffc21c-3ac7-49b6-854b-a2a97caf24e6",
        "protocol": "https",
        "name": null,
        "read_timeout": 60000,
        "port": 80,
        "path": "/posts",
        "updated_at": 1522978237,
        "retries": 5,
        "write_timeout": 60000
    }

And route

       {
            "created_at": 1522979692,
            "strip_path": true,
            "hosts": [
                "jsonplaceholder.typicode.com"
            ],
            "preserve_host": true,
            "regex_priority": 0,
            "updated_at": 1522979911,
            "paths": null,
            "service": {
                "id": "9cffc21c-3ac7-49b6-854b-a2a97caf24e6"
            },
            "methods": [
                "GET"
            ],
            "protocols": [
                "http",
                "https"
            ],
            "id": "b780ab68-8ff6-4c13-98f4-72e9944c1107"
        }

How can i access to url? localhost:8000/post not working.

You need this for your route if you want to invoke backend by path based, you have hosts populated which means you would need to add that Host to your request Header for it to work in current state, make a route like this:

       {
            "created_at": 1522979692,
            "strip_path": true,
            "hosts":null,
            "preserve_host": true,
            "regex_priority": 0,
            "updated_at": 1522979911,
            "paths":  [
                "/post"
            ],
            "service": {
                "id": "9cffc21c-3ac7-49b6-854b-a2a97caf24e6"
            },
            "methods": [
                "GET"
            ],
            "protocols": [
                "http",
                "https"
            ],
            "id": "b780ab68-8ff6-4c13-98f4-72e9944c1107"
        }

-Jeremy

thanks for the answer @jeremyjpj0916
in previous versions of kong i consume the routes without ‘host’ header. (register APIS)

localhost:8000/api1/posts
localhost:8000/api2/peoples

etc.
how can I do it in the new version using services and routes??

In the past, that was your API resource with the “uri” set. In Serices/Routes. This is defined by your Route “paths” argument. In the new architecture a Service just represents your backend endpoint and some timeout info.

1 Like

So, i declared my service as

{
    "host": "jsonplaceholder.typicode.com",
    "created_at": 1522992584,
    "connect_timeout": 60000,
    "id": "9cffc21c-3ac7-49b6-854b-a2a97caf24e6",
    "protocol": "https",
    "name": null,
    "read_timeout": 60000,
    "port": 80,
    "path": null,
    "updated_at": 1523042241,
    "retries": 5,
    "write_timeout": 60000
}

And my route as

{
“created_at”: 1523008492,
“strip_path”: true,
“hosts”: null,
“preserve_host”: false,
“regex_priority”: 0,
“updated_at”: 1523041707,
“paths”: [
“/myApi”
],
“service”: {
“id”: “9cffc21c-3ac7-49b6-854b-a2a97caf24e6”
},
“methods”: [
“GET”
],
“protocols”: [
“http”,
“https”
],
“id”: “b780ab68-8ff6-4c13-98f4-72e9944c1107”
}

and when i consume the url

localhost:8000/myApi/posts

the response is

An invalid response was received from the upstream server

please help me with this configuration.

http://jsonplaceholder.typicode.com/posts is a valid URL for you to create a Kong Route with GET to proxy to this service . your Service reveals a

"host": "jsonplaceholder.typicode.com",

and a

 "path": null,

you need your Service path

"path": "/posts"

So you route to http://jsonplaceholder.typicode.com/posts , which is your intended backend URL.

Hello, I’m facing the same issue when I create a service and then a route. I tried your solution.
Here the code

service declaration
{
“host”:“127.0.0.1”,
“created_at”:1533831880,
“connect_timeout”:60000,
“id”:“209cdc20-b1bc-4c91-a280-d14fef0140ae”,
“protocol”:“http”,
“name”:“wl-ms-job”,
“read_timeout”:60000,
“port”:8600,
“path”:"/jobs",
“updated_at”:1533835366,
“retries”:5,
“write_timeout”:60000
}

routes declaration
{
“next”:null,
“data”:[
{
“created_at”:1533834633,
“strip_path”:true,
“hosts”:null,
“preserve_host”:false,
“regex_priority”:0,
“updated_at”:1533834633,
“paths”:[
“/jobs”
],
“service”:{
“id”:“209cdc20-b1bc-4c91-a280-d14fef0140ae”
},
“methods”:null,
“protocols”:[
“http”,
“https”
],
“id”:“068a5110-42d6-4eb0-86d5-be26e5e999e2”
}
]
}

thanks

How about you try this(I am running Kong 0.14):

Service

{
  "host": "jsonplaceholder.typicode.com",
  "created_at": 1533879066,
  "connect_timeout": 60000,
  "id": "7f0d12e5-20ca-4f40-b8bb-67f1be0b97c5",
  "protocol": "https",
  "name": "Test_Jeremy",
  "read_timeout": 60000,
  "port": 443,
  "path": "/users",
  "updated_at": 1533879066,
  "retries": 5,
  "write_timeout": 60000,
  "extras": {
    "createdUser": null,
    "updatedUser": null,
    "id": 6,
    "service_id": "7f0d12e5-20ca-4f40-b8bb-67f1be0b97c5",
    "kong_node_id": "1",
    "description": null,
    "tags": null,
    "createdAt": "2018-08-10T05:31:06.000Z",
    "updatedAt": "2018-08-10T05:31:06.000Z"
  }
}

Route

{
  "created_at": 1533879076,
  "strip_path": true,
  "hosts": null,
  "preserve_host": false,
  "regex_priority": 0,
  "id": "a4adbc19-29e9-4bc1-93b5-c4af9a911c81",
  "paths": [
    "/users"
  ],
  "service": {
    "id": "7f0d12e5-20ca-4f40-b8bb-67f1be0b97c5"
  },
  "updated_at": 1533879076,
  "protocols": [
    "http",
    "https"
  ],
  "methods": null,
  "extras": {}
}

This will give you a working proxy to the test JSON website : https://jsonplaceholder.typicode.com/users if you are just looking to teset Kong proxy functionality.

And what kind of issues do you face?