luraproject / lura

Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
https://luraproject.org
Other
6.35k stars 564 forks source link

Cannot POST #224

Closed rjpalermo1 closed 5 years ago

rjpalermo1 commented 5 years ago

I give and need help...

fair to mid level experience with APIS, looking for alternative to Kong and love the message of KrakenD but cannot make progress on even the simple stuff.

brew install on MAC

I cannot do a simple POST. Can do GETs all day long (although the blacklist filter does not work for me) but trying a simple POST to an endpoint cannot get anything except

[GIN] 2019/03/21 - 09:50:44 | 500 |  635.863781ms |             ::1 | POST     /addresses
Error #01: Invalid status code

Here is my json file created from Designer:

{
    "version": 2,
    "extra_config": {
        "github_com/devopsfaith/krakend-cors": {
            "allow_methods": [
                "GET",
                "POST",
                "PUT",
                "DELETE",
                "PATCH"
            ],
            "allow_credentials": false,
            "allow_headers": [
                "Accept-language",
                "Content-Type"
            ]
        }
    },
    "timeout": "3000ms",
    "cache_ttl": "300s",
    "output_encoding": "json",
    "name": "Proto",
    "port": 8099,
    "endpoints": [
        {
            "endpoint": "/addresses",
            "method": "POST",
            "extra_config": {},
            "output_encoding": "json",
            "concurrent_calls": 1,
            "backend": [
                {
                    "url_pattern": "/v2/5c9392b53100004b00554606",
                    "method": "POST",
                    "encoding": "json",
                    "extra_config": {},
                    "sd": "static",
                    "host": [
                        "http://mocky.io"
                    ],
                    "disable_host_sanitize": false,
                    "is_collection": false,
                    "target": "",
                    "group": "address"
                }
            ],
            "headers_to_pass": [
                "Content-Type"
            ]
        }
    ]
}

CONSOLE

krakend run -c ./config/krakend.json -d -p 8099
Parsing configuration file: ./config/krakend.json
 ERROR: unable to create the gologging logger: getting the extra config for the krakend-gologging module
 ERROR: unable to create the GELF writer: getting the extra config for the krakend-gelf module
 INFO: Listening on port: 8099
 WARNING: building the etcd client: unable to create the etcd client: no config
 INFO: registering usage stats for cluster ID 'brQmdi2hZsBwl1c8BsEqhzwT99GqToO8xN6c95dwCrg='
 DEBUG: creating a new influxdb client
 DEBUG: no config for the influxdb client. Aborting
 WARNING: influxdb: unable to load custom config
 WARNING: opencensus: no extra config defined for the opencensus module
 DEBUG: no config for the bloomfilter
 WARNING: bloomFilter: no config for the bloomfilter
[GIN-debug] [WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

 WARNING: no config present for the httpsecure module
 DEBUG: Debug enabled
[GIN-debug] GET    /__debug/*param           --> github.com/devopsfaith/krakend-ce/vendor/github.com/devopsfaith/krakend/router/gin.DebugHandler.func1 (4 handlers)
[GIN-debug] POST   /__debug/*param           --> github.com/devopsfaith/krakend-ce/vendor/github.com/devopsfaith/krakend/router/gin.DebugHandler.func1 (4 handlers)
[GIN-debug] PUT    /__debug/*param           --> github.com/devopsfaith/krakend-ce/vendor/github.com/devopsfaith/krakend/router/gin.DebugHandler.func1 (4 handlers)
 DEBUG: CEL: no extra config detected for backend /v2/5c9392b53100004b00554606
 DEBUG: CEL: no extra config detected for pipe /addresses
 INFO: JOSE: singer disabled for the endpoint /addresses
 INFO: JOSE: validator disabled for the endpoint /addresses
[GIN-debug] POST   /addresses                --> github.com/devopsfaith/krakend-ce/vendor/github.com/devopsfaith/krakend/router/gin.CustomErrorEndpointHandler.func1 (4 handlers)

What am I doing wrong here?

kpacha commented 5 years ago

Hi @rjpalermo1 and welcome to the KrakenD community!

TL;DR: I think the problem is with the selected backend hostname. Changing to http://www.mocky.io will fix it.

I've been testing this configuration:

{
    "version": 2,
    "timeout": "3000ms",
    "cache_ttl": "300s",
    "name": "Proto",
    "port": 8099,
    "endpoints": [
        {
            "endpoint": "/addresses/ko",
            "method": "POST",
            "backend": [
                {
                    "url_pattern": "/v2/5c9392b53100004b00554606",
                    "host": [ "http://mocky.io" ],
                    "group": "address"
                }
            ],
            "headers_to_pass": [ "Content-Type" ]
        },
        {
            "endpoint": "/addresses/ok",
            "method": "POST",
            "backend": [
                {
                    "url_pattern": "/v2/5c9392b53100004b00554606",
                    "host": [ "http://www.mocky.io" ],
                    "group": "address"
                }
            ],
            "headers_to_pass": [ "Content-Type" ]
        }
    ]
}

Notice both endpoint are identical to your configuration (without the not needed params). The only difference between them is the host (and the endpoint url pattern).

$ curl -id'{"a":42}' localhost:8099/addresses/ko
HTTP/1.1 500 Internal Server Error
X-Krakend: Version 0.8.0
X-Krakend-Completed: false
Date: Thu, 21 Mar 2019 14:41:27 GMT
Content-Length: 0

$ curl -id'{"a":42}' localhost:8099/addresses/ok
HTTP/1.1 200 OK
Cache-Control: public, max-age=300
Content-Type: application/json; charset=utf-8
X-Krakend: Version 0.8.0
X-Krakend-Completed: true
Date: Thu, 21 Mar 2019 14:41:30 GMT
Content-Length: 39

{"address":{"response":"Hello Ladies"}}

The reason is a combination of two factors:

rjpalermo1 commented 5 years ago

YES!

That was it. All good now.

Will close this and open another regarding the filter blacklist. (UPDATE: FIXED)

Thank you for your quick reply!

github-actions[bot] commented 2 years ago

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.