Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
How do I get the return statement from JavaScript's Fetch?

Now I'm using Fetch to fetch some data from an API in SpringBoot.

const onSubmit = (data) => {
    fetch("http://localhost:8080/addMedicine", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(data),
    });
  };

Here is the Java code.

 @PostMapping("/addMedicine")
    public String addMedicine (@RequestBody Medicine medicine){
        return medicineService.addMedicine(medicine);
    }

 public String addMedicine(Medicine medicine) {
        medicineRepository.save(medicine);
        System.out.println("Added medicine "+ medicine.getMedicineName());
        return "Added medicine "+ medicine.getMedicineName() ;
    }

The above methods are from different classes I just put them here to simplify my question.

Now when I use Postman I get the statement like "Added medicine X"

Now when I post the data from my Frontend app which is in React. I want to get that statement so that I can use it to display something on the page as a confirmation.

How am I going to do it or for more info how does even Postman do it because it looks so easy from them? Please help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this should work :

const onSubmit = (data) => {
    fetch("http://localhost:8080/addMedicine", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(data),
    }).then(data=>{


      // Do something ....


    })
  };
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda