Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
How can I send data on a get and receive a return?

I have to send this data in a get request but I don't know how to do it. Can you help me?

const ROUTE = "public/v1/route";

export async function showRoute(
  flow: string,
  token: string
): Promise<RouteParams> {
  const response = await client.get(ROUTE);
  return response.data;
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I think what you're looking for is the Fetch-API. For example,

const ROUTE = resourcePath + '?' + new URLSearchParams({ ...params })

fetch(ROUTE) // sends a GET request
  .then((res: Response) => res.json() as MyExpectedDataType) // parses JSON response content
  .then((data: MyExpectedDataType) => {
    // do something with data
  })
  .catch(err => {
  })

// or
async function showRoute(): Promise<Something> {
  try {
    const res: Response = await fetch(ROUTE)
    const data = await res.json() as MyExpectedDataType
    // do something with data
  }
  catch (err) {
  }
}

fetch returns a Promise type on which you can chain asynchronous callbacks using .then and handle errors with .catch and .finally. You can also pass request method, headers, body content etc. as an optional second argument to fetch, see the documentation.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use async/await or .then() promise chaining:

import {showRoute} from './path-to-showRoute'

showRoute(/* params */).then(data => sendGetRequest(data))

//or

async function sendRouteInfo(){
  const routeData = await showRoute(/* params */)
  if (routeData) sendGetRequest(routeData)
}

PS: sendGetRequest is a mock function which simply sends a get request using axios or fetch

about 4 years ago · Juan Pablo Isaza Relatório

0

axios.get(${URL}) .then(response => console.log(response.data) .catch(err)=> console.log(err)


That is when you are using axios (npm i axios) then import it

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda