I have two routes
GET http://localhost:8081/api/books/exists?isbn=fdsfs
GET http://localhost:8081/api/books/:isbn
when calling first api it triggers second api because of path , it considers “exists” as path parameter for :isbn
how to resolve this.
Hi @JeevanKumar ,
Is this still the issue ??
@Simphiwe Yes.
Given API document has 4 GET request for same endpoints ,
I think In SSD I can’t able to rearrange the routes , like we put dynamic route under the other routes
for example :
get ("/books/exists");
get("/books/:isbn");
in above endpoints :isbn conflict with exists and get book :id conflict with paginated endpoint.
Can you share a screenshot of how you specified your endpoint and paths on you http-In for both
Hi @JeevanKumar ,
It seems like those are two different endpoints.
It should consider those to be completely different endpoints since they are not the same.
Can you also share a screenshot of the responses you get and their complete URL when calling them as a screenshot, please.
@Simphiwe
URL 1
http://localhost:8081/api/books/OL7353617M
URL 2
http://localhost:8081/api/books/exists?isbn=OL7353617M
here 404 is getting from URL 1
Could you provide a link to the document about handling dynamic routes in studio, or please explain it here.
Hi @JeevanKumar ,
Am trying to understand how they are conflicting coz they are not supposed to be conflicting since their endpoints are not the same.
They also don’t seem to be conflicting from my side since you are getting different responses, looks like one is getting the book and the other one is checking if the book exists.
Could you please provide more Information about what you mean when you say conflicting.
@Simphiwe
I mean , when I calling two different endpoints it gives response from one http flow in ssd
I Created 2 flows for 2 URL
URL 1 http://localhost:8081/api/books/OL7353617M
URL 2 http://localhost:8081/api/books/exists?isbn=OL7353617M
when I calling URL 2 , the backend assumes I am calling URL 1 and its returns response form URL 1 . the string “exists” (actually path of URL 2) is considered as isbn that’s why it returns error
{
"error" : "Book not found for ISBN: exists"
}
Hi @JeevanKumar ,
Thank you for confirming.
I see what you mean now, have went through the conflicting APIs.
In Express, routes are matched in the order they are defined, and dynamic parameters like :isbn will match any value, including the word "exists". If /books/:isbn is placed before /books/exists, a request to /books/exists will be treated as if "exists" is an ISBN, causing the static route to never be reached.
Always define more specific static routes first (like /books/exists) before dynamic ones (like /books/:isbn). To fix this in Neutrinos studio cut/books/:isbn flow and paste it at the end of all your apis.
That should work.
3 Likes