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

192
Visualizações
Pass a prop value as a query string to a sveltekit endpoint

I'm trying to pass a prop value from a text input field to a Sveltekit endpoint, but I can't figure out how I pass it through.

My onsubmit runs this function

const handleSubmit = () => {
        promise = getData();
    }

Which calls a function to get data from an external API via a sveltekit endpoint:

 async function getData() {
        const response = await self.fetch('api/address.json');
        const addressdata = await response.json()

        if (response.ok) {
        return addressdata;
            
        } 
}

The end point looks like this

export async function get({ }) {
    const baseurl = 'https://myaddressapi/?postcode=xxxxxx'
    const res = await fetch(baseurl, {
        method: 'GET',
        headers: {'Accept': 'application/json',
                'APIKey': 'mykey'}
        })
    const data = await res.json()

    if (res.ok) {
        return {
            status: 200,
            body: data
        }
    }

    return {
        status: res.status,
        error: new Error('This is an error')
    }
}

I want to be able to do something like:

const response = await self.fetch('api/address.json', {props:{searchInput}});

and then capture it on the endpoint:

export async function get(request, props)
const baseurl = 'https://myaddressapi/?postcode='
const url = `${baseurl}${props}`

I've tried to look at the documentation, but I can't seem to get it to work. Any pointers, please?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I re-read the docs, and I needed to pass the postcode as an ID into the endpoint, which is now working.

More information here - https://kit.svelte.dev/docs/routing#endpoints

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