1

I want to consume my api. it is in go lang. i use axios in front (react) for consume it

my route:

localhost:1323/profile/email/:email/password/:password

i don't know how i can pass the email and password in axios request with get.

my code:

import axios from 'axios'

    export async function validLogin(email, password) { 
      const valid = await axios.get('localhost:1323/profile/email/'+ email + '/password/'+ password).then((response) => {
        return response;
      });
      return valid
    }

I tried to use http://localhost instead localhost pure, but don't work too.

1
  • Don't pass passwords through URLs, they are likely to get recorded in log files. Authentication should be done through POST requests (or Authorization headers). Commented Jun 8, 2022 at 15:53

1 Answer 1

1
  • You need the scheme.
  • You need to encode special characters (like @!) before shoving them into the URL.
  • Template strings save on concatenation

Such:

const url = `http://localhost:1323/profile/email/${encodeURIComponent(email)}/password/${encodeURIComponent(password)}`
Sign up to request clarification or add additional context in comments.

Comments

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.