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

207
Views
Obtener datos de la API local Next.js

Hoy me encontré con un problema en la API de Next.js. Quería obtener datos de mi API interna en getStaticProps, pero como dice la documentación, no debe obtener su API local en getStaticProps y, en su lugar, debe importar la función. Pero, ¿y si quisiera enviar un índice de página a mi API local y obtener la página específica? No puedo hacer req.body.page aquí, entonces, ¿cómo obtengo los datos?

mi API se ve así

 export const getData = async (page) => { const data = await fetch( `https://rickandmortyapi.com/api/character?page=${page}` ); const response = await data.json(); return response; }; export default async function getCharactersAPI(req, res) { //here I would like to get the data that of the page (something like req.body.page) //and do something like const data = await getData(req.body.page) const data = await getData(); res.status(200).json(data); }

y mi código de búsqueda se ve así

 export const getStaticProps = async pageContext => { //here I would like to put the page I want to fetch in the getCharactersAPI() //and do something like const query = await getCharactersAPI(3), meaning page number 3 const query = await getCharactersAPI(); const response = await query.json(); return { props: { response }, }; };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El pageContext contiene los parámetros de URL, que presumiblemente tiene el número de página que desea obtener.

Así que extraiga la información de pageContent y luego llame a su consulta.

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!