invalid basepath results in 200 OK status code

Hi all,

When I'm trying to hit the apigee url with invalid basepath using postman, it is giving 200 OK status code with empty response content.

I am expecting that it should return a 404.

Did any one face the same issue?

0 2 1,332
2 REPLIES 2

Can you provide specific information?

When I try this, I get a 404.

$ curl -i https://ORG-ENV.apigee.net/invalidpath
HTTP/1.1 404 Not Found
Date: Fri, 05 Jan 2018 18:27:41 GMT
Content-Type: application/json
Content-Length: 167
Connection: keep-alive


{"fault":{"faultstring":"Unable to identify proxy for host: secure and url: \/invalidpath","detail":{"errorcode":"messaging.adaptors.http.flow.ApplicationNotFound"}}}

Is it possible you have made an invalid assumption?

By the way, it is possible to configure an API Proxy to listen on / , the root path. If you do that, then that API proxy will handle all requests that don't match the base path for any other API proxy. which means sending a request to /invalidpath would reach that "root proxy". If you have it set up this way, and if your root proxy responds with 200 OK, then it would produce the results you are reporting.

As Dino mentioned, I am also getting 404 error if it's an invalid base path.

My assumption is that you meant that you have a correct base path but non existing resource path

e.g. https://ORG-ENV.apigee.net/validpath/invalidresource

I think there are two ways you can get a 200 ok results in this case:

  1. If you are using the proxy as reverse proxy; meaning that you have a valid target endpoint, your target endpoint is also returning the a 200 ok status regardless of the validity of the resource requested.
  2. If you are not using a target endpoint, the default response to any resource request will return a 200 ok status even if the resource does not exist.

If you want to have a 404 status returned, one way you can do it is to create a Raise fault policy with 404 status if that requested endpoint does not match any of the endpoints defined in your proxy.

here's the simplest code to do just that:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows>
        <Flow name="validPath-1">
            <Description>valid</Description>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/valid1") and (request.verb = "GET")</Condition>
        </Flow>
        <Flow name="validPath-2">
            <Description>valid</Description>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/valid2") and (request.verb = "GET")</Condition>
        </Flow>
               
        <Flow name="invalid">
            <Description>invalid Path</Description>
            <Request>
                <Step>
                    <Name>RF-NotFound</Name>
                </Step>
            </Request>
            <Response>
            </Response>
        </Flow>
    </Flows>
    <HTTPProxyConnection>
        <BasePath>/quicktest</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="noroute"/>
</ProxyEndpoint>

and the raise fault policy can just be

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="RF-NotFound">
    <DisplayName>RF-NotFound</DisplayName>
    <Properties/>
    <FaultResponse>
        <Set>
            <Headers/>
            <Payload contentType="text/plain"/>
            <StatusCode>404</StatusCode>
            <ReasonPhrase>Not Found</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>