Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dispatching]Cannot add 2 different API resources with same end URL Template - 404 Error #1095

Closed
Sumudu-Sahan opened this issue Mar 1, 2021 · 2 comments · Fixed by ballerina-platform/module-ballerina-http#461

Comments

@Sumudu-Sahan
Copy link

Description:
Cannot use 2 different API resources with same last URL template values. When invoking the 2nd API resource, will receive 404 response code.

Steps to reproduce:
You can reproduce the issue by using the below code segment.

  • Resource 1: /path/{id}
  • Resource 2: /path/{noteasdf}/aa/{id}
import ballerina/http;
http:ListenerConfiguration helloWorldEPConfig = {
    secureSocket: {
        keyStore: {
            path: "/Users/viraj/Documents/APIM-2/resolve_merge/viraj_4/product-microgateway/distribution/target/wso2am-micro-gw-macos-3.2.2-SNAPSHOT/runtime/bre/security/ballerinaKeystore.p12",
            password: "ballerina"
        }
    }
};
service hello on new http:Listener(8181, helloWorldEPConfig) {
    @http:ResourceConfig {
        methods: ["GET"],
        path: "/path/{id}"
    }
    resource function sayHello2(http:Caller caller,
        http:Request req) returns error? {
        check caller->respond("Hello, World - 2!");
    }
    @http:ResourceConfig {
        methods: ["GET"],
        path: "/path/{noteasdf}/aa/{id}"
    }
    resource function sayHello3(http:Caller caller,
        http:Request req) returns error? {
        check caller->respond("Hello, World! 3");
    }
}
@Sumudu-Sahan Sumudu-Sahan changed the title Cannot add 2 API resources with same UR Template - 404 Error Cannot add 2 API resources with same URL Template - 404 Error Mar 1, 2021
@Sumudu-Sahan Sumudu-Sahan changed the title Cannot add 2 API resources with same URL Template - 404 Error Cannot add 2 different API resources with same end URL Template - 404 Error Mar 1, 2021
@anupama-pathirage anupama-pathirage transferred this issue from ballerina-platform/ballerina-lang Mar 12, 2021
@chamil321 chamil321 changed the title Cannot add 2 different API resources with same end URL Template - 404 Error [Dispatching]Cannot add 2 different API resources with same end URL Template - 404 Error Jun 4, 2021
@chamil321
Copy link
Contributor

Suggested solution might help to understand the behaviour when fixing the issue. Hence.

These are the three main resources of the API which are subjected to the fore-mentioned issue. 

notebook/{id} 
notebook/{notebookId}/entry/{id}
/notebook/{notebookId}/entry/{notebookEntryId}/content/{id}

Here, the id parameter has three separate meanings across the three resources. What we have to suggest is to make it consistent such that the same parameter does not have various meanings. And that is the best practice to follow when writing an API (even though it is not governed by the openapi spec). This approach can be used until this issue is fixed. In that case, the resources would look like this. 

notebook/{notebookId} 
notebook/{notebookId}/entry/{notebookEntryId}
/notebook/{notebookId}/entry/{notebookEntryId}/content/{id}

@chamil321
Copy link
Contributor

Duplicate of #342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants