1

I make API call in react like below.
First, there is an API address in html script.

<script
      type="text/javascript"
      src="https://dapi.kakao.com/v2/maps/sdk.js?appkey=s=services"
></script>

Second, get some result using method.

getCoor = () => {
    console.log(this.addressState.departure.road);


const geocoder = new window.daum.maps.services.Geocoder();

geocoder.addressSearch(this.addressState.departure.road, (result, status) => {
      if (status === window.daum.maps.services.Status.OK) {
        console.log(result[0].x, result[0].y);
      }
    });
  };

And, now I wanna make this in Nodejs.
But I don't know where I should put the method function in the POST request.
Could you recommend some solution?

 rp({
        method: 'POST',
        uri: `https://dapi.kakao.com/v2/maps/sdk.js?appkey=${
          process.env.DAUM_GEOCODE
        }&libraries=services`,
        data:{}
      })
        .then((response) => {
          console.log(response);

 })}
6
  • 2
    You should never try to execute arbitrary JS on your Node server. Remember, "eval is evil" Commented May 3, 2019 at 10:05
  • 5
    you can use axios, github.com/axios/axios Commented May 3, 2019 at 10:06
  • Seblor Could you give me more information about arbitrary JS? it's bcz I don't understand well even though i searched it. Commented May 3, 2019 at 10:49
  • GeekSambhu How can I put function or method in axios? Commented May 3, 2019 at 10:50
  • 1
    What I mean by "arbitrary JS" is (in your case) JavaScript code that is fetched from a website you have no control over. Even if you have control over it, some people could add malicious code that may destroy your app / server, and is overall a huge security flaw. Commented May 3, 2019 at 11:09

1 Answer 1

1

You can use axios! fro api calling...

const axios = require('axios')   

 axios({
      method: 'post',
      url: '/user/12345',
      data: {
        firstName: 'Fred',
        lastName: 'Flintstone'
      }
    });

axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you but, how can I use 'geocoder.addressSearch(this.addressState.departure.road' this in axios to get the result?
What is geocoder.addressSearch it looks like some method calling
Yes, that is a method calling. But when I use axios , i guess I can't use method calling on it. Am I correct?
axios only send request to the server with some data which you have to provide first execute you method and send the result according to the api

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.