Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Why is this catch all API route not working?

SO I been learning NextJS API routes and NodeJS recently, While I do know how to create dynamic routes now, I have some issues with a few things -

This is my api/matches.js file.

// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

export default async function handler(req, res) {
  const response = await fetch(`https://exampleapi.com/?&token=# `)
  const jsonData = await response.json();
  res.status(200).json(jsonData);

}

Now, I have another dynamic route for this API which fetches the match by a match slug, So this file was called /api/matches/[...matchslug].js

export default async function handler(req, res) {
const  page  = req.query.matchslug
const response = await fetch(`https://examleapi.com/?search[slug]=${page}&token=# `)
const jsonData = await response.json();

While this dynamic route fetches the result of one so if I went matches/exampelmatch, I do get the results for the examplematch, However I'm looking to somehow implement it in a way that

matches/examplematch1/examplematch2

Returns the data from the examplematch1 & examplematch2.

I'm not sure if building something like is possible, But very interested.

Thank you for your time and patience.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your /api/matches/[...matchslug].js example, the value of matchslug will always be an array.

Instead of passing the page variable directly into fetch, you can map over the values in the matchslug array and use Promise.all to request each resource.

It would look something like this (I haven't tested this):

export default async function handler(req, res) {
  const promiseArray = req.query.matchslug.map(async (slug) => {
    const response = await fetch(`https://examleapi.com/?search[slug]=${slug}&token=# `)
    const jsonData = await response.json();
    return jsonData
  })
  const result = await Promise.all(promiseArray)
  res.status(200).json(result);
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!