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

125
Views
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 answers
Answer question

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 Report

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 Report

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 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!