I am getting a 404 with a custom api when using a parameter
this is my wasp api
api getPexels {
httpRoute: (GET, "/api/get-pexels/:query"),
fn: import { getPexels } from "@src/server/pexels.js",
}
this is my api call
const res = await api.get(
and this is my backend function export const getPexels: GetPexels<{ query: string }> = async (req, res, context) => { console.log('pexels called');
/api/get-pexels?query=${selectedCity}
);
and this is my backend function export const getPexels: GetPexels<{ query: string }> = async (req, res, context) => { console.log('pexels called');
2 Replies
Hi @haarismian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It seems like you are trying to use a query parameter in your API call, but your API is expecting a route parameter.
In your Wasp API declaration, you have defined a route parameter
:query
:
However, in your API call, you are using a query parameter ?query=${selectedCity}
:
To fix this, you should change your API call to use a route parameter instead of a query parameter. Here's how you can do it:
This way, selectedCity
will be passed as a route parameter and should be accessible in your backend function as req.params.query
.
For more information on how to create and use APIs in Wasp, you can refer to the Wasp documentation (https://wasp-lang.dev/docs/advanced/apis).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @haarismian, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Kapa is correct 🙂 using
:query
means you are defining a route parameter and the route expects /api/get-pexels/something